Tuesday, 10 September 2013

Can create file but not Overwrite files in Documents directory with IOS

Can create file but not Overwrite files in Documents directory with IOS

I am writing a few files to the Documents directory, all is fine but when
I try and overwrite them they error.
I should add this is on the Simulator and the error is (NULL) when output
(trying to test on device but proving a little hard). I am wondering if I
need to set the file protection at point of writing?
// File Name
fileName = [NSString stringWithFormat:@"%@.plist", somefileName];
// Lookup a place to store the file
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,
NSUserDomainMask,
YES);
NSString *documentsDirectoryPath = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectoryPath
stringByAppendingPathComponent:fileName];
// Write the files
error = nil;
if (![data writeToFile:filePath options:NSDataWritingFileProtectionNone
error:&error])
{
[data writeToFile:filePath atomically:NO];
}
else
{
NSLog(@"Error writing file : %@, %@", fileName, error);
}

No comments:

Post a Comment