iphone SDK:Can write data to plist on Simulator bu

2019-01-28 09:42发布

问题:

Why I can write information to plist on simulator

But can't do this on real iphone/ipod device ????

Is there exist an absolute path to put a .plist file in xcode project ???

Thanks for all reply and answers ~

code : this how I write text to plist from textfield

NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Password" ofType:@"plist"];
NSMutableDictionary *propertyList = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
[propertyList setValue:serialNumber.text forKey:@"serial_number"];

回答1:

You can only write to your application's sandbox directory. Below is a function that will return the path to the Documents folder for you app.

- (NSString *)applicationDocumentsDirectory
{
    return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
}