I have created one plist in my resource file and i am adding items to plist for exm:
plistarray=[NSMutableArray arrayWithContentsOfFile:@"/Users/mangomac2/Desktop/chat module/complete (iphoneDesign) 2/picture-vide 2/Data.plist"];
if (plistarray==nil)
plistarray=[NSMutableArray array];
[plistarray addObject:datadict];
[plistarray writeToFile:@"/Users/ma开发者_开发技巧ngomac2/Desktop/chat module/complete (iphoneDesign) 2/picture-vide 2/Data.plist" atomically:YES];
[datadict release];
my data is adding to plist but whenever i m uploading my code to device its not adding to plist and not retrieving to plist also.
Please tell me where did i do mistake.
First off, you are hard-coding the path into your app, without any consideration for the fact that the app will be installed in different locations on the simulator on the device, and possibly in different locations on every different device as well. And second, it seems you are trying to update a file inside your application bundle; this is not allowed, and may fail if iOS enforces the non-writability of the app bundle using filesystem permissions.
To locate a file in your bundle, you should use the appropriate methods of the NSBundle class. For example, to get the path to the file Data.plist you might use [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"]
.
If you are wanting to modify this file, you must first copy it to a writable location (and then in the future read it back from this location instead of from your bundle). You can get appropriate directories using NSSearchPathForDirectoriesInDomains. For example, [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
will give you the path to your app's Documents directory. You can then use something like [directory stringByAppendingPathComponent:@"Data.plist"]
to get the full path and filename for a place you can store your Data.plist.
精彩评论