我正致力于通过UIWebViews
加载本地存储的网页的应用程序。用户退出后,我想删除所有网页'本地数据,例如cookie和HTML5数据库。我找到了这个解决方案并且有效:
how to remove html5 local storage of an iOS app using UIWebview
但是,在应用程序关闭然后重新启动之前,不会反映本地数据的删除,就像只有在启动应用程序时才将信息加载到RAM中。这是我的代码:
// Remove cookies
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (NSHTTPCookie *cookie in [cookieStorage cookies]) {
[cookieStorage deleteCookie:cookie];
}
// Remove HTML local storage
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *path = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
NSArray *fileArray = [fileManager contentsOfDirectoryAtPath:path error:nil];
for (NSString *file in fileArray) {
if ([file.pathExtension isEqualToString:@"localstorage"])
[fileManager removeItemAtPath:[path stringByAppendingPathComponent:file] error:nil];
}
我还添加了这条线,希望它可以解决问题,它没有工作:
[[NSURLCache sharedURLCache] removeAllCachedResponses];