应用程序在 [[NSBundle mainBundle] pathForResource 处崩溃

发布于 2024-12-06 01:56:01 字数 737 浏览 0 评论 0原文

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

[[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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒中人 2024-12-13 01:56:01

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文