CGFontCreateWithDataProvider hangs in airplane mode

后端 未结 1 1217
面向向阳花
面向向阳花 2020-12-25 08:11

When I make a call to CGFontCreateWithDataProvider while in airplane mode, my apps freeze. Not in airplane mode, it works fine. The font is s

相关标签:
1条回答
  • 2020-12-25 08:55

    I found the answer after a bit more searching.

    According to the following bug report: https://alpha.app.net/jaredsinclair/post/18555292

    If there’s no network connection, CGFontCreateWithDataProvider() hangs in a semaphore trap if it’s called during appDidFinishLaunchingWithOptions. Calling it in the next run loop works without hanging.

    As noted in the same post, calling

    [UIFont familyNames]

    before CGFontCreateWithDataProvider()

    resolves the issue. My code now looks like this and works as expected:

    + (void)registerIconFontWithURL:(NSURL *)url
    {
        NSAssert([[NSFileManager defaultManager] fileExistsAtPath:[url path]], @"Font file doesn't exist");
        CGDataProviderRef fontDataProvider = CGDataProviderCreateWithURL((__bridge CFURLRef)url);
    
        //THE NEXT LINE IS RELEVANT PART
        [UIFont familyNames];
    
        CGFontRef newFont = CGFontCreateWithDataProvider(fontDataProvider);
        CGDataProviderRelease(fontDataProvider);
        CFErrorRef error;
        CTFontManagerRegisterGraphicsFont(newFont, &error);
        CGFontRelease(newFont);
    }
    
    0 讨论(0)
提交回复
热议问题