此时,我的应用程序在设备中崩溃了,

[[NSBundle mainBundle] pathForResource

我在这里给出pdf的路径。但是在执行时,它表明它没有到达那里的路径。这可能是导致崩溃的原因。

但是它可以在模拟器上完美运行。

我不知道为什么会这样

这是代码
NSString *path = [[NSBundle mainBundle] pathForResource:[myArray objectAtIndex:0] ofType:[myArray objectAtIndex:1]];
NSLog(@"array elemt :%@", [myArray objectAtIndex:0]);
NSLog(@"array elemt 1 :%@", [myArray objectAtIndex:1]);
NSLog(@"path is :%@",path);
NSLog(@"responds to selector mainBundle=%@",[NSBundle respondsToSelector:@selector(mainBundle)]?@"YES""NO");
NSURL *targetURL = [NSURL fileURLWithPath:path];

在该路径的日志中-当我使用设备时,它向我显示nil,而当我使用模拟器时,它向我显示路径。它向我显示NSURL行崩溃

最佳答案

我发现,当类似的东西在模拟器上起作用而在设备上不起作用时,字符串的大小写可能有问题。您的设备区分大小写,但不区分计算机。检查文件名或类型的字符串。

关于iphone - 应用程序在[[NSBundle mainBundle] pathForResource崩溃,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7510717/

10-10 20:51