繁体   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