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:
Code Block 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<CFError>? |
if !CTFontManagerRegisterGraphicsFont(font, &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?