解决删除nsuserdefault全部内容后创建uiwebview挂机

在ios5.1中会出现的一个问题,令我很困扰,找了英文资料才知道原因.
程序里先显示了一个web,然后清空NSUserDefault,再去打开uiwebview,出现如下的错误提示:
-[__NSCFDictionary setObject:forKey:]: attempt to insert nil value (key: WebKitLocalStorageDatabasePathPreferenceKey)
这个情况只会在ios5.1中出现。
原因是在清空NSUserDefault时把key:
WebKitLocalStorageDatabasePathPreferenceKey对应的value也删出了,只要把这个对应的值加上就可以了。
id workaround51Crash = [[NSUserDefaults standardUserDefaults] objectForKey:@"WebKitLocalStorageDatabasePathPreferenceKey"]; NSDictionary *emptySettings = (workaround51Crash != nil) ? [NSDictionary dictionaryWithObject:workaround51Crash forKey:@"WebKitLocalStorageDatabasePathPreferenceKey"] : [NSDictionary dictionary]; [[NSUserDefaults standardUserDefaults] setPersistentDomain:emptySettings forName:[[NSBundle mainBundle] bundleIdentifier]];

你可能感兴趣的:(解决删除nsuserdefault全部内容后创建uiwebview挂机)