I'm working on an application which loads locally stored webpages through UIWebViews
. After the user logs out, I'd like to remove all of the webpages' local data, such as cookies and HTML5 databases. I found this solution and it works:
how to remove html5 local storage of an iOS app using UIWebview
However, the removal of the local data is not reflected until the application is closed and then relaunched, it's like the information is loaded to RAM only when the app is launched. This is my code:
// 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];
}
I also added this line hoping it would fix the problem, it didn't work:
[[NSURLCache sharedURLCache] removeAllCachedResponses];