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 find the path to is in the project. To check, look in the list of project files for the file; if it is not there, drag it.
Make sure that the file you are trying to download is copied to the application. To do this, click on the project under the project files (blue bar with the project name in it โ Click on the target object โ Click on โSet up phasesโ โ Click to expand โCopy copy resourcesโ and make sure your file is in it. If it is not, click on the plus and add it.
Make sure the case matches exactly. (aka - The simulator will work / the application will not have problems) Make sure that the case matches exactly, otherwise it will not return anything. To fix this, simply rename it to the project or use the correct source in the source.
The project may not have a multimedia environment. To fix this, click on the menu of your project โ click on the target โ click to expand "Link Binary Files to Libraries". Now select MediaPlayer.framework and create the code.
If all else fails, clear the project and try again.
All this is checked / fixed, but it does not work. Everything was fine with me, and I changed the video that I show in the application. Since I changed the file, it stopped working.
NSString *path = [[NSBundle mainBundle] pathForResource:@"multiplying" ofType:@"m4v"];
Q: why is it equal to zero? The file is correctly selected / correctly set and is about 10 megabytes. (too large a file?) It works well in the simulator, and I can get the path to the image, above the line, without errors.
source share