Post

Replies

Boosts

Views

Activity

Reply to Hang when opening share sheet
After I was still seeing the behavior when just creating an App Delegate, Scene Delegate, and View Controller that did just about nothing else, I deleted all other code in the app. I could then see the problem was gone. I then put a breakpoint in every method with a dispatch_once_t call. That led me to where my code was being called that I did not expect. I hope this is somehow helpful, @SeanMcMains! John
Sep ’22
Reply to Hang when opening share sheet
The crash report said the reason was running out of memory. The app's memory usage would climb by roughly 30MB/second until the app crashed. I since figured out the source of the problem. I had an Objective-C extension on UIColor that implemented secondaryLabelColor. I do not know why that had the effect it did on share sheets, but removing that extension method fixed it. Thank you for replying! John
Sep ’22
Reply to "Archiving error" when using a custom font
FYI, I got this helpful response to my FB, and it worked for me. I hope it helps you as well: You can’t use CTFontRegisterGraphicsFont() created from a CGDataProvider for widgets. Instead you can use CTFontManagerRegisterFontsForURL() and it is much simpler than the code you attached:         let bundle = Bundle(for: MyFonts.self)         let url = bundle.url(forResource: "miso-light", withExtension: "otf")!         var error: Unmanaged<CFError>?         if !CTFontManagerRegisterFontsForURL(url as CFURL, .process, &error) {             print("unable to register font: \(error!.takeUnretainedValue())")         } else {             print("registered!")         }
Sep ’20
Reply to WidgetKit and shared object instances
I ended up with a static method that reads a JSON file and returns it as a struct. That method caches the previous result in memory, and uses that result again if the JSON file is unchanged. The JSON file is generated by my app. It contains a small subset of the data from my app's sqlite database, primarily because I wanted to avoid 0xdead10cc crashes.
Sep ’20
Reply to Registering custom fonts from a framework in a widget extension
Thank you. I wonder if you can help me understand what I am doing wrong. I created a small sample project with this code shared between the app and the extension: class SharedFont {     static let fontName = "Miso-Bold"     static func registerFont() {         guard let url = Bundle.main.url(forResource: "miso-bold", withExtension: "otf") else {             print("could not find font file")             return         }         print("registering font at \(url.absoluteString)")         guard let fontDataProvider = CGDataProvider(url: url as CFURL) else {             print("Could not create font data provider for \(url).")             return         }         guard let font = CGFont(fontDataProvider) else {             print("could not create font")             return         }         var error: Unmanaged&lt;CFError&gt;?         if !CTFontManagerRegisterGraphicsFont(font, &amp;error) {             print(error!.takeUnretainedValue())         }     } } If I call SharedFont.registerFont() in my AppDelegate didFinishLaunchingWithOptions method, the font is available to the app. The font is in both the app target and in the widget target. Either that same method does not work in a Widget extension, or perhaps I am putting it in the wrong place. I tried calling this in my TimelineProvider’s snapshot(…) function and in its timeline(…) function. The font does work in the extension or in the SwiftUI previews of the view in the extension. Is there a better place in a Widget extension to put this type of one-time initialization code that might let it work?
Jul ’20