Я впервые реализую пакет настроек, и я сделал это, создав Root.plist и Child.plist в Settings.bundle и имея несколько полей в этом plist. Мне нужно обновить поля (добавить или удалить) Child.plist в соответствии с веб-службами, и я написал для этого код в appdelegate. Он отлично работает в симуляторе (все поля обновляются соответственно), но не работает в устройстве. Может ли кто-нибудь предложить мне, что может быть причиной этого.
код, чтобы скопировать plist в каталог документов и обновить его (согласно ответу)
NSString *bundle = [[NSBundle mainBundle]pathForResource:@"Settings" ofType:@"bundle"];
NSString *path = [bundle stringByAppendingPathComponent:@"Category.plist"];
NSMutableDictionary *dictOfPlist = [NSDictionary dictionaryWithContentsOfFile:path];
NSMutableArray *dictArray = [dictOfPlist valueForKey:@"PreferenceSpecifiers"];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path1 = [documentsDirectory stringByAppendingPathComponent:@"Child.plist"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath: path1])
{
[fileManager copyItemAtPath:path toPath: path1 error:&error];
}
for (some condition)
{
// creating dictionary
// add dictionary to array dictArray
}
[dictOfPlist setObject:dictArray forKey:@"PreferenceSpecifiers"];
[dictOfPlist writeToFile:path1 atomically:YES];