应用程序在[[NSBundle mainBundle] pathForResource [英] Application crashes at [[NSBundle mainBundle] pathForResource
问题描述
我的应用程式目前在装置中发生崩溃,
My Application is crashes in the device at this point,
[[NSBundle mainBundle] pathForResource
我给出了pdf的路径。但在执行时它表明它没有得到路径。这可能是崩溃的原因。
I am giving the path for the pdf here . but at the execution time it is showing that it is not getting path there . and that may be the reason for crashing.
但是它在模拟器上运行完美。
however it is running perfectly on simulator .
我无法弄清楚为什么会发生这种情况
i am not able to figure out why is this happening
这里是代码
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
行
in this log of the path - when i use device it is showing me nil
and when i use simulator it is showing me the path . and it is showing me that is is crashing on NSURL
line
推荐答案
我发现,当这样的东西在模拟器上工作,但不是在设备上,这可能是一个问题的字符串的情况。您的设备区分大小写,但不是您的计算机。请检查文件名或类型的字符串。
I've found that when something like this works on the simulator, but not on the device, it's likely a problem with the case of the string. Your device is case sensitive but not your computer. Check your string of the file name or the type.
这篇关于应用程序在[[NSBundle mainBundle] pathForResource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!