簡體   English   中英

訪問應用程序捆綁包中包含的文件

[英]Accessing to files included in the app bundle

以下代碼在iOS 8之前運行良好。現在,我正在為iOS 8 beta 5進行編譯,無法訪問這些文件。

NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
sprintf(appPath, "%s/%s/extfiles", [NSHomeDirectory() UTF8String],
[[[NSFileManager defaultManager] displayNameAtPath:bundlePath] UTF8String]);

應用程序路徑的結果應類似於:

appPath char *  "/var/mobile/Containers/Data/Application/97726814-AA76-41AB-A9A7-296AAEF4F898/MyApplication.app/extfiles"   0x0054f44c

我的應用程序使用該文件夾中包含的文件來啟動,因此結果是我的應用程序在讀取文件時崩潰。

該代碼不正確,並且不應在任何版本的iOS上運行,因為將應用程序包根目錄和主目錄串聯起來是沒有意義的。 如果有效,那么我認為這很幸運。

您想要的是:

NSBundle *bundle = [NSBundle mainBundle];
NSURL *extFilesURL = [[bundle resourceURL] URLByAppendingPathComponent:@"extfiles"];

您可以嘗試一下

NSString *str=[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"extfiles"];

希望能幫助到你。

暫無
暫無

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

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