how to remove html5 local storage of an iOS app using UIWebview(如何使用 UIWebview 删除 iOS 应用程序的 html5 本地存储)
问题描述
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 website Data" that removes cookies/local storage. I know how to do the cookies but i am unable to figure out how to remove/clear the later (local storage)
How to remove HTML5 persistant databases in UIWebView? discussed this but i didn't see how that works for my above case. localStorage.clear() javascript needs to be run in UIWebview stringByEvaluatingJavaScriptFromString() method but this didn't seem to have worked in my testing. The other concern with the above approach is that, localStorage is url/site specific - but i want to clear all the contents inside localStorage.
Tried removing/copying Appln/Library/WebKit/LocalStorage folder - but this didnt work out with access restriction errors.
Any suggestions/directions please ?
You should be able to do it cleaning the content of the Caches directory of your app:
EDIT: Update code as suggested by @RaphaelSchweikert because of wrong error management.
// first, remove the cookies.
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies]) {
[storage deleteCookie:cookie];
}
NSString *path = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil];
for (NSString *string in array) {
NSLog(@"Removing %@", [path stringByAppendingPathComponent:string]);
if ([[string pathExtension] isEqualToString:@"localstorage"])
[[NSFileManager defaultManager] removeItemAtPath:[path stringByAppendingPathComponent:string] error:nil];
}
Inside that folder on my simulator I see many .localstorage files ;-) Try and let me know
这篇关于如何使用 UIWebview 删除 iOS 应用程序的 html5 本地存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 UIWebview 删除 iOS 应用程序的 html5 本地存储
基础教程推荐
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01