2018-08-29 ios清理LocalStorage

NSString filePath = [[NSBundle mainBundle] pathForResource:@"storage" ofType:@"html"];
NSURL url = [NSURL fileURLWithPath:filePath];
NSData data = [NSData dataWithContentsOfURL:url];
_wkWebView = [[WKWebView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height
0.5)];
_wkWebView.backgroundColor = [UIColor greenColor];
[self.view addSubview:_wkWebView];
[_wkWebView loadData:data MIMEType:@"text/html" characterEncodingName:@"UTF-8" baseURL:url];
_wkWebView2 = [[WKWebView alloc]initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height
0.5, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height
0.5)];
[self.view addSubview:_wkWebView2];
_wkWebView2.backgroundColor = [UIColor redColor];
[_wkWebView2 loadData:data MIMEType:@"text/html" characterEncodingName:@"UTF-8" baseURL:url];
}

  • (IBAction)clearLocalStorageAction:(id)sender {
    [_wkWebView2 evaluateJavaScript:@"localStorage.clear()" completionHandler:^(id _Nullable object, NSError * _Nullable error) {

    }];
    [_wkWebView2 reload];
    [_wkWebView reload];
    }

  • (IBAction)reLoadWebURLAction:(id)sender {
    [_wkWebView reload];
    }

原生退出登录 清理已经移除的释放wkwebview的存储 存储好像和url相关 _wkWebView2需要load相关页面才能调用js localStorage.clear()不报错 推测应该要求_wkWebView2和_wkWebView的url在同一个scheme下

你可能感兴趣的:(2018-08-29 ios清理LocalStorage)