簡體   English   中英

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

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM