NSBundle mainBundle pathForResource(也许不是同一个问题)
问题:[NSBundle mainBundle] pathForResource 返回 null (0x0)
我阅读了很多有关此主题的帖子,以下是我发现的内容:
确保您尝试获取路径的文件位于项目中。要进行检查,请在项目文件列表中查找该文件,如果不存在,请将其拖放到其中。
检查您尝试加载的文件是否已复制到应用程序。为此,单击项目文件下的项目(其中带有项目名称的蓝色条 - >单击目标 - >单击构建阶段 - >单击展开“复制捆绑资源”,并确保您的文件如果不在其中,请单击加号,然后添加它。
- 目标->单击“构建阶段”->单击展开“ 完全匹配(又名 - 模拟器将工作/应用程序不会出现问题)确保大小写完全匹配,否则它将不返回任何内容,只需在项目中重命名它,或在源中使用正确的大小写。
项目可能缺少媒体框架。要解决此问题,请单击项目菜单 ->点击目标->单击展开“链接二进制文件与库”。现在选择 MediaPlayer.framework 并构建代码。
如果所有其他方法都失败,请清理项目,然后重试。
所有这些都已检查/修复,但不起作用。我的工作正常,然后我更改了应用程序中显示的视频。自从我更改了文件后,它就停止工作了。
<代码> NSString *path = [[NSBundle mainBundle] pathForResource:@"乘法" ofType:@"m4v"];
问:为什么为空?该文件大小写匹配/输入正确,大小约为 10 兆。 (文件太大了吗?)在模拟器中工作正常,我可以获得图像的路径,在该图像的上面一行,没有错误。
Problem : [NSBundle mainBundle] pathForResource returns null (0x0)
I read a lot of posts on this topic, here is what I found:
Make sure the file you are trying to get a path to, is in the project. To check, look in the project file list for the file, if it is not there, drag and drop it in.
Check that the file your trying to load is being copied to the app. To do this, click on project under project files (blue bar with project name in it->Click on the target->Click on Build Phases->Click to expand the "copy Bundle Resources", and make sure your file is in it. If it is not, click the plus, and add it.
Make sure the case matches exactly. (aka - The simulator will work/the app will not problem) Make sure the case matches exactly, otherwise it will return nothing. To fix this, just rename it in the project, or use the right case in the source.
Project may be missing the media framework. To fix this click on your project menu -> click on the target -> click to expand "Link Binary With Libraries". Now select MediaPlayer.framework and build the code.
If all else fails, clean the project, and try again.
All this is checked/fixed, but not working. I had this working fine, and then I changed the video that I am showing in the app. Since i changed the file, it stopped working.
NSString *path = [[NSBundle mainBundle] pathForResource:@"multiplying" ofType:@"m4v"];
Q: why is it null? The file is case matched/typed correctly and is about 10 megs. (is the file too large?) Works fine in the simulator, and I can get the path to an image, a line above this one, with no error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你说它在模拟器中工作但在设备上不起作用?
也许您应该尝试在第一次启动时将文件复制到应用程序沙箱文件夹之一并按如下方式访问它:
You say it's working in simulator and not working on device?
May be you should try to copy the file at first launch to one of the application sandbox folders and access it like this: