更新子程序plogramit在模拟器中显示但不在设备中显示

时间:2013-10-16 12:34:29

标签: ios settings.bundle

我第一次实现设置包,我通过在Settings.bundle中创建Root.plist和Child.plist来完成它,并在这些plist中有一些字段。 我需要根据Web服务更新Child.plist的字段(添加或删除),我已经在appdelegate中编写了代码。它在模拟器中工作正常(所有字段都相应更新)但它不在设备中工作。 任何人都可以告诉我它可能是什么原因。

将plist复制到文档目录并更新(根据asnwer)的代码

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

1 个答案:

答案 0 :(得分:1)

我认为你写一个PLIST有问题。您需要将资源包中的PLIST复制到文档目录中,并修改此文件夹中的PLIST。

为此你可以使用这段代码:

NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"data.plist"];

NSFileManager *fileManager = [NSFileManager defaultManager];

if (![fileManager fileExistsAtPath: path])
{
    NSString *bundle = [[NSBundle mainBundle] pathForResource:@”data” ofType:@”plist”];
     [fileManager copyItemAtPath:bundle toPath: path error:&error];
}

看看here

相关问题