[英]File not found on iOS device, but works in Simulator
当我在模拟器上测试我的应用程序时,一切正常。 但是当我在我的iOS设备上测试时,我收到此错误:
*** Terminating app due to uncaught exception 'FileNotFound', reason: 'file '/Users/name/Documents/appname/GFX/MainMenu.png' not found'
我检查了Build Phases Copy Bundle Resources并添加了所有内容。 当我在Xcode
突出显示该文件时,将在实用程序中检查目标成员身份。
我也尝试省略加载文件的代码,但我在不同的文件上得到相同的错误。 似乎只有应用程序图标和启动图像正确加载。
请注意,我正在使用Sparrow Framework (如果这有任何区别)。 纹理加载如下:
SPTexture *gameMenuTexture = [SPTexture textureWithContentsOfFile:(@"/Users/name/Documents/appname/GFX/MainMenu.png")];
SPImage *gameMenuImage = [SPImage imageWithTexture:(gameMenuTexture)];
[self addChild:gameMenuImage];
将非常感谢帮助。 我在各个论坛上寻找答案。 谢谢!
问题是硬编码路径:
@"/Users/name/Documents/appname/GFX/MainMenu.png"
在设备中,指定路径中不会有任何文件夹。
如果是捆绑使用:
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"MainMenu" ofType:@"png"];
SPTexture *gameMenuTexture = [SPTexture textureWithContentsOfFile:filePath];
测试像这样的SPTexture *gameMenuTexture = [SPTexture textureWithContentsOfFile:(@"MainMenu.png")];
您的模拟器只是Mac上运行的应用程序。 它可以轻松访问我们Mac上的文件,例如/Users/name/Documents/appname/GFX/MainMenu.png。
您的iOS设备无法直接访问Mac上的文件。 最新发布应用时,第三方用户几乎无法访问Mac上的任何内容。
想想吧。 它确实有所作为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.