簡體   English   中英

將文件夾添加到iPad捆綁包適用於模擬器,而不適用於設備

[英]Adding folder to iPad bundle works on simulator, not on device

我的應用有兩個目標。
每個都有其自己的文件Info.plist和一個自定義文件夾(作為引用,而不是組)。
當我在模擬器上運行目標時,該文件夾已正確插入捆綁包中,並且可以毫無問題地讀取其中的文件。
這是讀取文件夾路徑的代碼:

NSBundle* mainBundle;
NSString *fileFolder;
mainBundle = [NSBundle mainBundle];
NSLog(@"Bundle path: %@", [mainBundle bundlePath]);
NSLog(@"Folder name: %@", [mainBundle objectForInfoDictionaryKey:@"CustomFolder"]);
NSString *folder = [mainBundle objectForInfoDictionaryKey:@"CustomFolder"];
fileFolder = [[[NSBundle mainBundle] pathForResource:folder ofType:nil] retain];
NSLog(@"Folder: %@", fileFolder);

如果我嘗試在設備上調試該應用程序,則捆綁路徑和文件夾名稱正確,但是文件夾字符串為null。
我已經檢查了我的應用程序產品的內部,並找到了包含所有文件的正確文件夾。
所以有什么問題? 這是讀取權限問題嗎?

更新在iPad Simulator中運行的結果路徑是這樣

/ * /庫/應用程序支持/ iPhone模擬器/4.3.2/Applications/8337B9E5-1BFE-4A17-969E-E3E6E43193D6/MyApp.app/CustomFolder/

更新2的問題是我添加了帶有“為任何添加的文件夾創建文件夾引用”的文件夾。
我用stringByAppendingPathComponent替換了pathForResource,但是問題仍然存在於subpathsOfDirectoryAtPath。

您必須確保使用iPad內存中的正確位置。 在模擬器上保存內容的位置沒有任何限制。 此代碼有效

+(NSString*) pathToDocumentsFolder
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return documentsDirectory;  
}
+(NSString*) pathToFileInDocumentsFolder:(NSString*)filename
{
NSString *pathToDoc = [NSBundle pathToDocumentsFolder];
return [pathToDoc stringByAppendingPathComponent:filename];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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