how to remove html5 local storage of an iOS app using UIWebview

后端 未结 2 1883
北荒
北荒 2020-12-17 06:20

I have an app that uses UIWebview which is used to browser different sites/urls. I am in need of an option \"clear client data\" similar to iOS mobile safari \"Remove All we

2条回答
  •  情书的邮戳
    2020-12-17 06:36

    Note, that, if you’re using PhoneGap, you’ll also have to clear their internal backup of the localstorage cache:

    //Remove the localstorage db
    NSString *path = [[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"Backups"] stringByAppendingPathComponent:@"localstorage.appdata.db"];
    [[NSFileManager defaultManager] removeItemAtPath:path error:nil];
    
    //Also remove the cached versions
    path = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
    for (NSString *string in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil]) {
        if ([[string pathExtension] isEqualToString:@"localstorage"]) {
            [[NSFileManager defaultManager] removeItemAtPath:path error:nil];
        }
    }
    

提交回复
热议问题