gpt4 book ai didi

ios - CGFontCreateWithDataProvider 在飞行模式下挂起

转载 作者:技术小花猫 更新时间:2023-10-29 10:57:37 25 4
gpt4 key购买 nike

当我调用 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、iPhone 5。

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

提前致谢!

最佳答案

经过更多的搜索,我找到了答案。

根据以下错误报告: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.

如同一篇文章所述,调用

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

关于ios - CGFontCreateWithDataProvider 在飞行模式下挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24900979/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com