[英]File not found on iOS device, but works in Simulator
When I test my app on the simulator, everything works fine. 当我在模拟器上测试我的应用程序时,一切正常。 But when I test on my iOS Device, I get this error:
但是当我在我的iOS设备上测试时,我收到此错误:
*** Terminating app due to uncaught exception 'FileNotFound', reason: 'file '/Users/name/Documents/appname/GFX/MainMenu.png' not found'
I checked the Build Phases Copy Bundle Resources and everything is added. 我检查了Build Phases Copy Bundle Resources并添加了所有内容。 When I highlight the file in
Xcode
, Target Membership is checked in utilities. 当我在
Xcode
突出显示该文件时,将在实用程序中检查目标成员身份。
I also tried omitting the code that loads the file, but I get the same error on a different file. 我也尝试省略加载文件的代码,但我在不同的文件上得到相同的错误。 It seems that only the app icons and launch images load properly.
似乎只有应用程序图标和启动图像正确加载。
Please note that I am using Sparrow Framework (if that makes any difference). 请注意,我正在使用Sparrow Framework (如果这有任何区别)。 The textures are loaded like so:
纹理加载如下:
SPTexture *gameMenuTexture = [SPTexture textureWithContentsOfFile:(@"/Users/name/Documents/appname/GFX/MainMenu.png")];
SPImage *gameMenuImage = [SPImage imageWithTexture:(gameMenuTexture)];
[self addChild:gameMenuImage];
Help will be much appreciated. 将非常感谢帮助。 I've looked all over forums for answers.
我在各个论坛上寻找答案。 Thanks!
谢谢!
Issue is with the hard coded path: 问题是硬编码路径:
@"/Users/name/Documents/appname/GFX/MainMenu.png"
In device there will not be any folder in the specified path. 在设备中,指定路径中不会有任何文件夹。
If it is on bundle use: 如果是捆绑使用:
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"MainMenu" ofType:@"png"];
SPTexture *gameMenuTexture = [SPTexture textureWithContentsOfFile:filePath];
测试像这样的SPTexture *gameMenuTexture = [SPTexture textureWithContentsOfFile:(@"MainMenu.png")];
Your simulator is just an application running on your Mac. 您的模拟器只是Mac上运行的应用程序。 It can easily access files on our Mac such as /Users/name/Documents/appname/GFX/MainMenu.png.
它可以轻松访问我们Mac上的文件,例如/Users/name/Documents/appname/GFX/MainMenu.png。
Your iOS device cannot directly access files on your Mac. 您的iOS设备无法直接访问Mac上的文件。 Latest when you distribute your app, the 3rd party users can hardly access anything on your Mac.
最新发布应用时,第三方用户几乎无法访问Mac上的任何内容。
Think it over. 想想吧。 It does make sence.
它确实有所作为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.