0

我已将以下内容添加到我的 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

尝试写入文件时似乎有问题。

4

1 回答 1

1

您正在更改应用程序包中的文件。这是苹果禁止的。检查这个:将 NSDictionary 写入我的应用程序包中的 plist

您必须将 plist 复制到允许更改的文件夹中,例如文档文件夹。

于 2012-09-07T04:48:35.500 回答