Fixing WebKitLocalStorageDatabasePathPreferenceKey crash

I’ve been getting a lot of crashes with the following signature:

[cc lang=”objc”]Exception Type: SIGABRT
Exception Codes: #0 at 0x351be32c
Crashed Thread: 0

Application Specific Information:
*** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[__NSCFDictionary setObject:forKey:]: attempt to insert nil value (key: WebKitLocalStorageDatabasePathPreferenceKey)’
[/cc]

What is this?. It’s pretty well explained here.
My workaround?. Quite simple. Call this method as soon as your app launches:

[cc lang=”objc”]
-(void)fixWebkitCrash
{
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
NSString* webkitPath = [defaults objectForKey:@”WebKitLocalStorageDatabasePathPreferenceKey”];
NSString* bundlePath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];

if([webkitPath containsString:bundlePath] == NO)
{
[defaults removeObjectForKey:@”WebKitLocalStorageDatabasePathPreferenceKey”];
[defaults synchronize];
}
}
[/cc]

Hopefully, this will save you a couple hours!.