Ios CGFontCreateWithDataProvider在飞行模式下挂起

Ios CGFontCreateWithDataProvider在飞行模式下挂起,ios,objective-c,fonts,freeze,Ios,Objective C,Fonts,Freeze,当我在飞行模式下呼叫CGFontCreateWithDataProvider时,我的应用程序冻结。不是在飞机模式下,它工作正常。字体存储在设备上,不应进行网络访问 调用此方法加载本地字体文件时: [self registerIconFontWithURL:[[NSBundle mainBundle] URLForResource:@"FontAwesome" withExtension:@"otf"]]; 以下方法中url的值为: file:///var/mobile/Applications

当我在飞行模式下呼叫CGFontCreateWithDataProvider时,我的应用程序冻结。不是在飞机模式下,它工作正常。字体存储在设备上,不应进行网络访问

调用此方法加载本地字体文件时:

[self registerIconFontWithURL:[[NSBundle mainBundle] URLForResource:@"FontAwesome" withExtension:@"otf"]];
以下方法中
url
的值为: file:///var/mobile/Applications/48D3DA14-235B-4450-A081-7A6BA6116667/Blah.app/FontAwesome.otf

+ (void)registerIconFontWithURL:(NSURL *)url
{
    NSAssert([[NSFileManager defaultManager] fileExistsAtPath:[url path]], @"Font file doesn't exist");
    CGDataProviderRef fontDataProvider = CGDataProviderCreateWithURL((__bridge CFURLRef)url);

//******Freezes after the next line******
    CGFontRef newFont = CGFontCreateWithDataProvider(fontDataProvider);
//******FROZEN******

    CGDataProviderRelease(fontDataProvider);
    CFErrorRef error;
    CTFontManagerRegisterGraphicsFont(newFont, &error);
    CGFontRelease(newFont);
}
iOS 7.1.x,iPhone5

我不知道为什么会发生这种情况,也没有找到任何帮助。有人知道为什么会发生这种情况吗


提前谢谢

我在进一步搜索后找到了答案

根据以下错误报告:

如果没有网络连接,CGFontCreateWithDataProvider()将挂起 在信号量陷阱中,如果在 appDidFinishLaunchingWithOptions。在下一次运行循环中调用它 无需吊死即可工作

正如在同一篇文章中所指出的那样

[UIFont familyNames]

CGFontCreateWithDataProvider()之前

解决问题。我的代码现在看起来像这样,并按预期工作:

+ (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);
}

发布相关代码。
url
的值是多少?@rmaddy你看得太早了,它现在就在那里=)为什么不使用
CTFontManagerRegisterFontsForURL()
?调用
[UIFont familyNames]修复了我的问题!哇!你是怎么想出来的:o@Hlung我在谷歌上搜索了一下,发现了我的答案中提到的bug报告…救了我=)哇,不错。你是怎么发现这个的?@ManuelM。一些幸运的/疯狂的Google=)这也解决了我的问题,尽管我没有在飞行模式下调用它(即,我有一个有效的网络连接)。我试图从UIFont的扩展调用它,在类'
initialize()
方法(这是Swift)的重写中。