应用程序在 [[NSBundle mainBundle] pathForResource 处崩溃
此时,我的应用程序在设备中崩溃,
[[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
行崩溃
My Application is crashes in the device at this point,
[[NSBundle mainBundle] pathForResource
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
here is that code
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];
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现当类似的东西在模拟器上运行但在设备上不起作用时,很可能是字符串大小写的问题。您的设备区分大小写,但您的计算机不区分大小写。检查文件名或类型的字符串。
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.