Can we save to NSUserDocuments?

It seems that it's not possible or I don't know how to do it


Do we need to change something to write data?


NSData *png = UIImagePNGRepresentation(image);

[png writeToFile:[FileSystem getPath:stationName ofType:@"png" inFolder:cache] atomically:YES];


Any help will be much welcome

PS: works on simulator, not in device

A bit more information


[self createFolder:@"test"];


+ (void)createFolder:(NSString*)folder

{

NSFileManager *fileManager = [NSFileManager defaultManager];


NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

NSString *thePath = [documentsPath stringByAppendingPathComponent:folder];


NSError *error = nil;

[fileManager createDirectoryAtPath:thePath withIntermediateDirectories:YES attributes:nil error:&error];

}


Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file “test” in the folder “Documents”." UserInfo={NSFilePath=/var/mobile/Containers/Data/Application/A64A699C-2441-49CF-8DA3-1188CC0E67D6/Documents/test, NSUnderlyingError=0x147d75170 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}

Accepted Answer

Local storage for documents isn't allowed. You can use caches though. But caches will be wiped.


Also NSUserDefaults, but there is a size limit I've been told.


Here's the forum link: https://forums.developer.apple.com/message/50152#50152

Thanks for that, will use Cache for that.


Here is path for future reference


NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];

Can we save to NSUserDocuments?
 
 
Q