我已将以下内容添加到我的 Cordova.plist 文件中:
Key: EnableEverything
Type: Boolean
Value: YES
然后我使用以下代码读取和写入 plist 文件:
NSString *adKey = @"EnableEverything";
NSString *pathToSettingsInBundle = [[NSBundle mainBundle] pathForResource:@"Cordova" ofType:@"plist"];
NSMutableDictionary *plist = [NSDictionary dictionaryWithContentsOfFile: pathToSettingsInBundle];
NSString *enableEverything = [[plist valueForKey:adKey] stringValue];
NSLog(@"EnableEverything: %@", enableEverything); // this returns 1, which is correct.
// Disable in plist.
[plist setValue:NO forKey:adKey];
[plist writeToFile:pathToSettingsInBundle atomically:YES];
NSLog(@"EnableEverything: %@", enableEverything); // never reaches this line
我收到以下错误:
2012-09-07 14:20:12.168 slq[958:707] *** WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate: <NSInternalInconsistencyException> -[__NSCFDictionary removeObjectForKey:]: mutating method sent to immutable object
尝试写入文件时似乎有问题。