iOS8 create directory operation not permitted

286 views Asked by At

Here's a strange problem for help. Need to install multiple app on iOS8, these have the same source code and resources, the only difference is CFBundleIdentifier and CFBundleDisplayName of these app.

Install two ipa on iOS8 device, the previous app will crash and the latest works fine!!

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    [self createStorage];
    //ASIDownloadCache *chache = [ASIDownloadCache sharedCache];
    return YES;
}

- (NSString*)storagePath
{
    return [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"ASIHTTPRequestCache"];
}

- (void)clearStorage
{
    NSFileManager *fileManager = [[NSFileManager alloc] init];
    BOOL isDirectory = NO;
    BOOL exists = [fileManager fileExistsAtPath:[self storagePath] isDirectory:&isDirectory];
    if (!exists || !isDirectory) {
        return;
    }
    NSError *error = nil;
    NSArray *cacheFiles = [fileManager contentsOfDirectoryAtPath:[self storagePath] error:&error];
    if (error) {
        NSLog(@"[CLEAR]IOS8 ERROR:%@", error);
        [NSException raise:@"FailedToTraverseCacheDirectory" format:@"Listing cache directory failed at path '%@'", [self storagePath]];
    }
}

// If install two versions app on iOS8. previous app will CRASH and latest works FINE.
- (void)createStorage
{
    [self clearStorage];
    NSFileManager *fileManager = [[NSFileManager alloc] init];
    BOOL isDirectory = NO;
    BOOL exists = [fileManager fileExistsAtPath:[self storagePath] isDirectory:&isDirectory];
    if (exists && !isDirectory) {
        [NSException raise:@"FileExistsAtCachePath" format:@"Cannot create a directory for the cache at '%@', because a file already exists", [self storagePath]];
    }

    NSError *error = nil;
    [fileManager createDirectoryAtPath:[self storagePath] withIntermediateDirectories:NO attributes:nil error:&error];
    if ( error )
    {
        NSLog(@"error for create directory: %@", error); 
        // previous app will crash. Organizer--->My Device--->Console output: \
                    error for create directory: Error Domain=NSCocoaErrorDomain Code=513 "The operation couldn’t be completed. (Cocoa error 513.)" UserInfo=0x178075140 {NSFilePath=/var/mobile/Containers/Data/Application/CC220B9D-4E02-4D78-A1DB-3E4A3DA3EEB7/Library/Caches/ASIHTTPRequestCache, NSUnderlyingError=0x178048f40 "The operation couldn’t be completed. Operation not permitted"}
        [NSException raise:@"FailedToCreateCacheDirectory" format:@"Failed to create a directory for the cache at '%@'", [self storagePath]];
    }
}

And I write a shell script, It can rewrite CFBundleIdentifier and CFBundleDisplayName, call xcrun generate new ipa file. I had commit the project and shell script to github. github link

0

There are 0 answers