how to update the plist file in ios [duplicate]

2019-09-21 20:42发布

问题:

This question already has an answer here:

  • iphone write to file fails 2 answers

I am developing one application.In that i am trying to update the plist file using below code.

 plist_path=[[NSBundle mainBundle]pathForResource:@"Configurationfile" ofType:@"plist"];
 config_dict=[[NSMutableDictionary alloc]initWithContentsOfFile:plist_path];
[config_dict setValue:textField.text forKey:@"ServerURL"];
NSLog(@"%@",config_dict);
[config_dict writeToFile:plist_path atomically:YES];
[config_dict release];

But it's not working.But NSlog showing the correct values for every key in the dictionary.Please help me how to update the plist file.

回答1:

You cannot update the files within the app bundle. Instead copy the files to a working directory and update them there.