【问题标题】:File not found on iOS device, but works in Simulator在 iOS 设备上找不到文件,但可以在模拟器中使用
【发布时间】:2012-12-21 08:38:21
【问题描述】:

当我在模拟器上测试我的应用时,一切正常。但是当我在我的 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 框架(如果这有什么不同的话)。纹理是这样加载的:

SPTexture *gameMenuTexture = [SPTexture textureWithContentsOfFile:(@"/Users/name/Documents/appname/GFX/MainMenu.png")];

SPImage *gameMenuImage = [SPImage imageWithTexture:(gameMenuTexture)];
[self addChild:gameMenuImage];

我们将不胜感激。我在论坛上到处寻找答案。谢谢!

【问题讨论】:

  • 你检查文件名了吗?它区分大小写。如果你忽略它,它可能在模拟器中工作

标签: iphone objective-c image file simulator


【解决方案1】:

问题在于硬编码路径:

@"/Users/name/Documents/appname/GFX/MainMenu.png"

设备中指定路径下不会有任何文件夹。

如果是捆绑使用:

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"MainMenu" ofType:@"png"];
SPTexture *gameMenuTexture = [SPTexture textureWithContentsOfFile:filePath];

【讨论】:

  • 谢谢!我现在明白了。
  • @Bromium:很高兴:)
【解决方案2】:

测试类似SPTexture *gameMenuTexture = [SPTexture textureWithContentsOfFile:(@"MainMenu.png")];的东西

【讨论】:

    【解决方案3】:

    您的模拟器只是在您的 Mac 上运行的应用程序。它可以轻松访问我们 Mac 上的文件,例如 /Users/name/Documents/appname/GFX/MainMenu.png。

    您的 iOS 设备无法直接访问 Mac 上的文件。最新发布应用程序时,第 3 方用户几乎无法访问您 Mac 上的任何内容。

    三思而后行。它确实有道理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多