简体   繁体   English

在iOS设备上找不到文件,但在Simulator中可以使用

[英]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.

相关问题 在iOS模拟器上可以使用,但在iOS设备上不能使用吗? - Works on iOS Simulator but not on iOS device? iOS应用程序可在模拟器上运行,但不能在设备上运行 - IOS application works on the simulator but not on the device AVAudioPlayer:MP3文件无法在设备上播放,但适用于模拟器(iOS 6) - AVAudioPlayer: MP3 file not playing on device, but works in Simulator (iOS 6) iOS应用程序在模拟器中以后台模式工作,但在设备中不工作吗? - iOS app works in background mode in simulator but not in device? iOS 10.3文本语音转换可在模拟器上运行,但不能在设备上运行 - iOS 10.3 text to speech works on simulator but not on device 应用程序在设备上崩溃但在模拟器 iOS 上工作 - App crash on device but works on simulator iOS iOS应用可在模拟器上运行,但不能在真实设备上运行 - iOS app works on simulator but not on real device iPhone应用程序无法在设备中创建文件,但可以在模拟器中使用 - iPhone app not making file in device but works in simulator iOS能够在模拟器上读取plist文件,但无法在设备上读取 - iOS able to read plist file on simulator but not on device iOS Core Audio渲染回调只能在模拟器上使用,而不能在设备上使用 - iOS Core Audio render callback works on simulator, not on device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM