Permission to create folders on iPhone

About halfway from digging, I found that I do not have permission to create folders, so how do I get permission to create folders?

[[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"} 
+4
source share
2 answers

You cannot change the contents of the compiled application folder. This is because the package is a compiled application. This prevents the possibility of malware modifying applications after installation.

Files created at runtime must be saved in the Documents , Temp or Cache folders. These folders are available only for your application. No other application can access the contents of these folders.

Code example:

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

Mark the answer below 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) 
+7
source

Source: https://habr.com/ru/post/1500146/


All Articles