tags:

views:

309

answers:

2

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?

+1  A: 

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)

Vladimir
A: 

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

James Raybould
working perfectly .. Thank you..
newbie