0
我首次實現了設置包,並且我通過在Settings.bundle中創建Root.plist和Child.plist並在這些plist中包含了一些字段來完成此操作。 我需要根據Web服務更新Child.plist的字段(添加或刪除),並且我已經在appdelegate中編寫了代碼。它在模擬器中工作正常(所有字段都相應更新),但它不能在設備中工作。 任何人都可以建議我可能是什麼原因。更新兒童plist在模擬器中顯示但未在設備中顯示
代碼複製到的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];
感謝您的回覆,我會執行並檢查它。 – Kapil
你嘗試過嗎? –
是的,我嘗試過,但它不工作,因爲我使用plist進行設置,如果我們在文檔目錄中創建子plist,則無法從Root.plist訪問它。請建議我如何從代碼更新孩子plist。 – Kapil