NSBundle mainBundle pathForResource(也许不是同一个问题) [英] NSBundle mainBundle pathForResource (maybe not the same problem)

查看:106
本文介绍了NSBundle mainBundle pathForResource(也许不是同一个问题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:[NSBundle mainBundle] pathForResource返回null(0x0)

Problem : [NSBundle mainBundle] pathForResource returns null (0x0)

我读了很多关于这个主题的帖子,这是我发现的:

I read a lot of posts on this topic, here is what I found:


  1. 确保您尝试获取路径的文件位于项目中。要检查,请在项目文件列表中查找该文件,如果不存在,请将其拖放。

  1. 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可能缺少媒体框架。要修复此项目菜单上的单击 - >单击目标 - >单击以展开Link Binary With Libraries。现在选择MediaPlayer.framework并构建代码。

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:@multiplyingofType:@ M4V];

问:为什么它为空?该文件正确匹配/输入,大约10兆。 (文件是否太大?)在模拟器中工作正常,我可以获得图像的路径,这一行之上的一行,没有错误。

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.

推荐答案

你说它在模拟器中工作而不在设备上工作?
可能你应该尝试在首次启动时将文件复制到其中一个应用程序沙箱文件夹并按如下方式访问:

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:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *pathForTheFile= [documentsDirectory stringByAppendingPathComponent:     @"multiplying.m4v"];

这篇关于NSBundle mainBundle pathForResource(也许不是同一个问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆