在iPad上调试UIAppFonts问题的建议 [英] Advice on Debugging a UIAppFonts Issue on iPad

查看:191
本文介绍了在iPad上调试UIAppFonts问题的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我发现这个帖子似乎描述了我加入我自己的ttf的同样的问题。我的应用程序冻结。然而,关于这个帖子的一些事情让我感到困惑,并且我很想得到一些帮助解密它。



这个帖子在这里: http://web.archiveorange.com/archive/v/nagQXB5eX3YsQpevIXMk



我想了解的相关章节如下:
$ b


附加调试器并暂停
应用程序
$ b

0 0xffff028f in __spin_lock



1 ?? / h1>

导致
问题的特定代码:

CTFontCollectionRef collection =
CTFontCollectionCreateFromAvailableFonts空值);
CFArrayRef fonts =
CTFontCollectionCreateMatchingFontDescriptors(collection); (NSArray
*)字体中的(id fontDescRef)
{CFStringRef fontName = CTFontDescriptorCopyAttribute((CTFontDescriptorRef)fontDescRef,
kCTFontNameAttribute); NSLog(@%@,
fontName); CFRelease(的fontName); }
CFRelease(fonts);
$ b $ p

执行不会超出
第二行。
blockquote>

问题:他是如何找出导致问题的线路和功能的?这是不是要显示反汇编,以混合模式显示,或在地图文件中查找十六进制值?


被要求提供演示版本和
,因此进一步调查,
我发现,如果代码是在我的
应用程序中,则问题显示
:didFinishLaunchingWithOptions:
但是如果我在
中有相同的东西,则不会显示viewDidLoad我的初始视图
控制器。

问题:这里提到的代码是什么?这个问题与通过plist值添加自定义字体有关,所以我不确定他可以指的是什么,或者我可以如何解决我的问题。



请帮助!

解决方案

嗯,没有任何关于解决这个职位,但我找到了一个解决方案张贴在苹果开发论坛。基本上,从applicationDidFinishLaunching fn调用它:

   - (NSUInteger)loadFonts {
NSUInteger newFontCount = 0;
NSBundle * frameworkBundle = [NSBundle bundleWithIdentifier:@com.apple.GraphicsServices];
const char * frameworkPath = [[frameworkBundle executablePath] UTF8String];
if(frameworkPath){
void * graphicsServices = dlopen(frameworkPath,RTLD_NOLOAD | RTLD_LAZY);
if(graphicsServices){
BOOL(* GSFontAddFromFile)(const char *)= dlsym(graphicsServices,GSFontAddFromFile);
if(GSFontAddFromFile)
for(NSString * fontFile in [[NSBundle mainBundle] pathsForResourcesOfType:@ttfinDirectory:nil])
newFontCount + = GSFontAddFromFile([fontFile UTF8String]);
}
}

return newFontCount;
}

并确保包含dlcfn.h并将dlsym的结果如下所示:
$ b (BOOL()(const char ))



没有改变原来的帖子,以防万一这个错误只是影响了我。


I recently found this post which seems to describe the same problem I am having with adding my own ttf. My app freezes. However, a few things about the post confuse me, and I'd love to get some help deciphering it.

The post is here: http://web.archiveorange.com/archive/v/nagQXB5eX3YsQpevIXMk

The relevant passages that I'm trying to understand are below:

Attaching the debugger and pausing the application reveals a not especially helpful call stack:

0 0xffff028f in __spin_lock

1 ??

Specific code that is causing the problem:

CTFontCollectionRef collection = CTFontCollectionCreateFromAvailableFonts(NULL); CFArrayRef fonts = CTFontCollectionCreateMatchingFontDescriptors(collection); for(id fontDescRef in (NSArray *)fonts) { CFStringRef fontName = CTFontDescriptorCopyAttribute((CTFontDescriptorRef)fontDescRef, kCTFontNameAttribute); NSLog(@"%@", fontName); CFRelease(fontName); }
CFRelease(fonts);

Execution never moves beyond the second line.

Question: How did he figure out what line and function was causing the problem? Was this something having to do with displaying the disassembly, showing it in mixed mode, or looking up a hex value in a map file? I'd like to learn how this was done.

Having been asked to supply a demo and hence having investigated further, I've found that the problem manifests if the code is in my application:didFinishLaunchingWithOptions: but not if I have the same stuff in the viewDidLoad of my initial view controller.

Question: what is 'the code' he's referring to here? The problem had to do with adding custom fonts through a plist value, so I'm not sure what he could be referring to or how I can workaround my issue.

Please Help!

解决方案

Well, nothing on figuring out this post, but I did find a workaround posted by someone on the apple dev forums. Basically, calling this from the applicationDidFinishLaunching fn:

- (NSUInteger) loadFonts {
     NSUInteger newFontCount = 0;
     NSBundle *frameworkBundle = [NSBundle bundleWithIdentifier:@"com.apple.GraphicsServices"];
     const char *frameworkPath = [[frameworkBundle executablePath] UTF8String];
     if (frameworkPath) {
          void *graphicsServices = dlopen(frameworkPath, RTLD_NOLOAD | RTLD_LAZY);
          if (graphicsServices) {
               BOOL (*GSFontAddFromFile)(const char *) = dlsym(graphicsServices, "GSFontAddFromFile");
               if (GSFontAddFromFile)
                    for (NSString *fontFile in [[NSBundle mainBundle] pathsForResourcesOfType:@"ttf" inDirectory:nil])
                         newFontCount += GSFontAddFromFile([fontFile UTF8String]);
          }
     }

     return newFontCount;
}

and making sure to include dlcfn.h and to cast the result of dlsym to the following:

(BOOL()(const char))

I did not alter the original post just in case this error was just something that affected me.

这篇关于在iPad上调试UIAppFonts问题的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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