I have added the following to my Cordova.plist file:
Key: EnableEverything
Type: Boolean
Value: YES
I then use the following code to read and write the plist file:
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
I get the following error:
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
There seems to be a problem when it’s trying to write to the file.
You are changing a file in the app bundle. This is prohibited by apple. check this: writing NSDictionary to plist in my app bundle
You have to copy the plist to a folder you are allowed to change, for example the documents folder.