0
처음으로 설정 번들을 구현하고 있으며 Settings.bundle에 Root.plist 및 Child.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];
답장을 보내 주셔서 감사합니다. 구현하고 확인해 보겠습니다. – Kapil
시도해 보셨습니까? –
예, 설정을 위해 plist를 사용하고 있으므로 문서 디렉토리에 child plist를 만들면 Root.plist에서 액세스 할 수 없기 때문에 작동하지 않습니다. 어떻게하면 코드에서 자식 plist를 업데이트 할 수 있는지 제안 해주십시오. – Kapil