CGFontCreateWithDataProvider以飞行模式挂起 [英] CGFontCreateWithDataProvider hangs in airplane mode

查看:259
本文介绍了CGFontCreateWithDataProvider以飞行模式挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在<飞行模式中调用 CGFontCreateWithDataProvider 时,我的应用程序将冻结。不在飞行模式,它工作正常。字体存储在设备上,不应该发生网络访问。



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

  [self registerIconFontWithURL:[[NSBundle mainBundle] URLForResource:@FontAwesomewithExtension:@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]], @字体文件不存在);
CGDataProviderRef fontDataProvider = CGDataProviderCreateWithURL((__ bridge CFURLRef)url);

// ******在下一行后面冻结******
CGFontRef newFont = CGFontCreateWithDataProvider(fontDataProvider);
// ****** FROZEN ******

CGDataProviderRelease(fontDataProvider);
CFErrorRef错误;
CTFontManagerRegisterGraphicsFont(newFont,& error);
CGFontRelease(newFont);
}

iOS 7.1.x,iPhone 5。

我不知道为什么会发生这种情况,并没有找到任何帮助。有没有人有一个线索,为什么会发生这种情况?



在此先感谢!

解决方案



根据以下错误报告:https://alpha.app.net/jaredsinclair/post/18555292


如果如果在
appDidFinishLaunchingWithOptions期间被调用,CGFontCreateWithDataProvider()会将
挂在一个信号量陷阱中。在下一个循环中调用它
不会挂起。


正如在同一篇文章中提到的,
$ b $ [UIFont familyNames]



之前 CGFontCreateWithDataProvider()



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

  +(void)registerIconFontWithURL:(NSURL *)url 
{
NSAssert([[NSFileManager defaultManager] fileExistsAtPath:[url path]],@字体文件不存在);
CGDataProviderRef fontDataProvider = CGDataProviderCreateWithURL((__ bridge CFURLRef)url);

//下一行是相关的部分
[UIFont familyNames];

CGFontRef newFont = CGFontCreateWithDataProvider(fontDataProvider);
CGDataProviderRelease(fontDataProvider);
CFErrorRef错误;
CTFontManagerRegisterGraphicsFont(newFont,& error);
CGFontRelease(newFont);
}


When I make a call to CGFontCreateWithDataProvider while in airplane mode, my apps freeze. Not in airplane mode, it works fine. The font is stored on the device, no network access should be happening.

While calling this method to load a local font file:

[self registerIconFontWithURL:[[NSBundle mainBundle] URLForResource:@"FontAwesome" withExtension:@"otf"]];

The value of url in the following method is: 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, iPhone 5.

I have no idea why this might happen and haven't been able to find any help out there. Does anyone have a clue why this might happen?

Thanks in advance!

解决方案

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

这篇关于CGFontCreateWithDataProvider以飞行模式挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆