Lord Zsolt
Lord Zsolt

Reputation: 6557

Permission to create folder on iPhone

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?

[[NSFileManager defaultManager] createDirectoryAtPath:[NSString stringWithFormat:@"%@/%@",downloadLocation,kAmazonCatalogsPrefix]
                          withIntermediateDirectories:YES
                                           attributes:nil
                                                error:&error];

Error Domain=NSCocoaErrorDomain Code=513 "The operation couldn’t be completed. (Cocoa error 513.)" UserInfo=0x1f18a8b0 {NSFilePath=/var/mobile/Applications/AB570058-4E4A-41B2-9E40-5C93316D6307/eCatalogs, NSUnderlyingError=0x1f18a830 "The operation couldn’t be completed. Operation not permitted"}

Upvotes: 4

Views: 6482

Answers (2)

PREMKUMAR
PREMKUMAR

Reputation: 8349

Check the below Answer for SWIFT:

var paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String

[NSFileManager.defaultManager().createDirectoryAtPath(paths.stringByAppendingPathComponent("Hello"), withIntermediateDirectories: false, attributes: nil, error: nil)]


println(paths)

Upvotes: 7

Bhavin
Bhavin

Reputation: 27225

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];

Upvotes: 7

Related Questions