0
我加入以下到我的Cordova.plist文件:寫入到PhoneGap的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
似乎有是一個問題,當它試圖寫入文件。