I think I may have found a solution.
None of the suggestions helped, as I already used the correct PostScript font name and all fonts had a name.
The original code that loaded the font looked like this, as in my original post:
guard let fontURL = Bundle.module.url(forResource: fontName, withExtension: ext),
let fontDataProvider = CGDataProvider(url: fontURL as CFURL),
let font = CGFont(fontDataProvider) else {
fatalError("Couldn't create font from filename: \(fontName).\(ext)")
}
var error: Unmanaged<CFError>?
CTFontManagerRegisterGraphicsFont(font, &error)
Which appears fine. It was code I copied from StackOverflow, and since it worked I just let it be. Now I spent some time reading about this method (CTFontManagerRegisterGraphicsFont), and it seems it has a sibling, called CTFontManagerRegisterFontsForURL (https://developer.apple.com/documentation/coretext/1499468-ctfontmanagerregisterfontsforurl). The main difference between these two methods, aside from one asking for a URL to the font file and another asking for the actual font, is that the latter takes another argument, namely scope, which can be one of none, process, persistent and session - see https://developer.apple.com/documentation/coretext/ctfontmanagerscope.
So I changed my code to this, using the process scope:
guard let fontURL = Bundle.module.url(forResource: fontName, withExtension: ext) else {
fatalError("Couldn't create font from filename: \(fontName).\(ext)")
}
var error: Unmanaged<CFError>?
CTFontManagerRegisterFontsForURL(fontURL as CFURL, .process, &error)
And it now seems it's resolved. I have not seen the fonts misbehaving since, and it's been several days of opening the app, working on it and such. I also want to clarify that in my original post, it was simply a case of UIFont returning nil for the requested font, and I had null coalesced a nil font to the system default, which added to my confusion with regard to the "swapping around" of fonts - something that did not happen.
I realise this does not help anyone not loading fonts from code like this.
Post
Replies
Boosts
Views
Activity
I just would like to say that I still have this problem on Xcode 15.2. I had hoped it would go away with 15.2, but no. No idea how to proceed or where to begin debugging this.
This is Instagram/Facebook's fault. They don't want users to leave their app for tracking/marketing purposes, so they prevent deep-linking from working correctly and deploy their own in-app browser to handle all links. There's nothing you can do about this.
What I've seen work is that if you navigate as a result of a click ( tag or onclick) to a different domain inside the in-app browser, it will work (most of the time).