Search code examples
iosobjective-cnsbundle

Accessing to files included in the app bundle


The following code works fine before iOS 8. Now I am compiling for iOS 8 beta 5 I can not access to those files.

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

The result of app Path should be like:

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

My application uses the files included in that folder to start so the result is that my app crashes upon reading the files.


Solution

  • That code isn't right and should not work on any version of iOS as it makes no sense to concatenate the app bundle root and the Home Directory. If it works then I assume that's just luck.

    What you want is:

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