Имам приложение, което чете информация от I plist файл. За да го направя, използвам този код по-долу:
NSData *plistData;
NSString *error;
NSPropertyListFormat format;
id plist;
localizedPath = [[NSBundle mainBundle] pathForResource:@"settings" ofType:@"plist"];
plistData = [NSData dataWithContentsOfFile:localizedPath];
plist = [NSPropertyListSerialization propertyListFromData:plistData mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&error];
if (!plist) {
NSLog(@"Error reading plist from file '%s', error = '%s'", [localizedPath UTF8String], [error UTF8String]);
[error release];
}
NSString *tel=[NSString stringWithFormat:@"tel:%@",[plist objectForKey:@"number"]];
NSURL *telephoneURL = [NSURL URLWithString:tel];
[[UIApplication sharedApplication] openURL:telephoneURL];
И за да го напиша, използвам този код:
- (IBAction) saveSetting:(id)sender{
NSData *plistData;
NSString *error;
NSPropertyListFormat format;
id plist;
NSString *localizedPath = [[NSBundle mainBundle] pathForResource:@"settings" ofType:@"plist"];
plistData = [NSData dataWithContentsOfFile:localizedPath];
plist = [NSPropertyListSerialization propertyListFromData:plistData mutabilityOption:NSPropertyListMutableContainers format:&format errorDescription:&error];
if (!plist) {
NSLog(@"Error reading plist from file '%s', error = '%s'", [localizedPath UTF8String], [error UTF8String]);
[error release];
}
NSLog([plist objectForKey:@"message"]);
[plist setValue:textMex.text forKey:@"message"];
NSLog([plist objectForKey:@"message"]);
NSLog([plist objectForKey:@"number"]);
[plist setValue:textNumero.text forKey:@"number"];
NSLog([plist objectForKey:@"number"]);
[plist setValue:@"NO" forKey:@"firstTime"];
[plist writeToFile:localizedPath atomically:YES];
[self aggiorna];
[settingScreen removeFromSuperview];
}
Сега имам голям проблем, приложението работи правилно във всички мои устройства за разработчици и в симулатора и приложението чете и записва правилно файла. Изпращам приложението в магазина на Apple, но други потребители не могат да четат/записват този файл. Защо това? Благодаря Паоло
[[NSDictionary dictionaryWithObjectsAndKeys:…stuff here…] writeToURL:myPlistURL atomically:YES];
| Прочетено:NSDictionary *settingsDict = [NSDictionary dictionaryWithContentsOfURL:myPlistURL];
- person   schedule 01.06.2011