Reputation: 1
I have written one application that save txt file into device. When I test on simulator, I am able to read and write file. After I test on device, read is working fine but it doesn't write anything on that text file. I have searched for the solution but it seems like it has problem with right access. Anyone can suggest me how to make this work?
Upvotes: 0
Views: 2457
Reputation: 5820
What path are you using to save the file to?
I'm using
- (NSString *)dataFilePath{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return [documentsDirectory stringByAppendingPathComponent:@"myFileNameHere.txt"];
}
and then pass [self dataFilePath];
into the writeToFile method as the path
Upvotes: 3
Reputation: 170849
On real device you don't have access to write everywhere. See "Commonly Used Directories" in Developers Guide - you should write to Documents or Caches directories (how to get their paths)
Upvotes: 2