Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
756 views
in Technique[技术] by (71.8m points)

objective c - iphone SDK:Can write data to plist on Simulator but can't do same thing at Device?

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"];
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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];
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...