2013-06-01 68 views
-3

我正在開發一個應用程序。在那裏我試圖用下面的代碼更新plist文件。如何更新ios中的plist文件

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

但它不工作。但NSlog顯示字典中每個鍵的正確值。請幫助我如何更新plist文件。

+0

Euh。我第一次遇到這個錯誤時,我搜索了這個綜合症,並且有很多關於這個不起作用的命中。這在StackOverflow上也被問過數百次。我不能相信你不能罰一個笨蛋。 – 2013-06-01 07:10:17

+0

[iphone寫入文件失敗]可能的重複(http://stackoverflow.com/questions/3386973/iphone-write-to-file-fails)和[this](http://stackoverflow.com/questions/3155952/iphone-writetofile-not-saving-new-entry-into-plist/3156393#3156393)和[this one](http://stackoverflow.com/questions/6368752/modifying-a-plist-is-not-working )和... – 2013-06-01 07:11:07

回答

0

您無法更新應用程序包中的文件。而是將文件複製到工作目錄並在那裏更新它們。