tags:

views:

208

answers:

1

I am new to iphone development.I have created plist such as from my previous post. It works well in simulator but not in device.Please help me out.Thanks.

EDIT:i am getting the saved value from the plist and checking for the condition.When i use simulator it works but not in device.

+1  A: 

(1) You can't write to a file in the resource folder of an iPhone. It is part of the security system of the phone that prevent malicious code from altering an application after it has been installed.

(2) If you want to save new data to a file you need to write the file to one of the automatically generated folders. Whenever an iPhone app is installed on the device or simulator, the system creates a default set of folders. It looks like this: http://yfrog.com/0wscreenshot20100412at115p

(3) You want to write to either the Preferences folder or the Documents folder. If the data concerns the operation of the app, write it to preferences. If it contains user data write to Documents.

Preferences:

NSArray *sysPaths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask, YES); 
NSString *prefsDirectory = [[sysPaths objectAtIndex:0] stringByAppendingPathComponent:@"/Preferences"];

Documents:

NSArray *sysPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory ,NSUserDomainMask, YES); 
NSString *docsDirectory = [sysPaths objectAtIndex:0];

Say you want to read a default preference plist file, make some changes and then save it the preferences folder.

NSString *plistPath=[[NSBundle mainBundle] pathForResource:@"PlistFileName" ofType:@"plist"];
NSMutableArray *defaultPrefs=[[NSMutableArray alloc] initWithContentsOfFile:plistPath];
//... modify defaultPrefs
NSString *outputFilePath=[prefsDirectory stringByAppendingPathComponent:@"alteredPrefs.plist"];
[defaultPrefs writeToFile:outputFilePath atomically:NO];
TechZen