Permission to create folder on iPhone

前端 未结 2 396
执念已碎
执念已碎 2021-01-14 02:09

After like a half an our of digging, I\'ve found out I don\'t have permission to create folders, so how do I get permission to create a folder?

[[NSFileManag         


        
2条回答
  •  佛祖请我去吃肉
    2021-01-14 03:11

    You cannot modify the contents of a compiled app's bundle folder. This is because the bundle is the compiled application. This prevents the possibility of malware modifying apps after install.

    Files generated at run time should be saved to the either Documents, Temp or Cache folders. These folders are only accessible to your app. No other app can access the contents of these folders.

    Sample Code :

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    
    NSError *error;
    [[NSFileManager defaultManager] createDirectoryAtPath:[documentsDirectory stringByAppendingPathComponent:@"yourFolderName"] withIntermediateDirectories:NO attributes:nil error:&error];
    

提交回复
热议问题