Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

ios - iphone write to file fails

I'm writing some data to a plist file but it fails on the device but not in the simulator. I'm lost, don't know where to look for a solution.

This is my code:

NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setObject:nameField.text forKey:@"name"];
[dict setObject:emailField.text forKey:@"email"];
BOOL ret = [dict writeToFile:[[NSString alloc] initWithString:[[NSBundle mainBundle] pathForResource:@"settings" ofType:@"plist"]] atomically:YES];
NSLog(@"%d",ret);
[dict release];

The log returns 0 on the device, but 1 in the simulator.

Can somebody help me out?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

Why are you trying to write in resource directory? Have you checked this?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...