Skip to content

Instantly share code, notes, and snippets.

@KC-218
Last active July 3, 2020 06:14
Show Gist options
  • Save KC-218/74f9f199e6d8da64f7a5c435eadc2736 to your computer and use it in GitHub Desktop.
Save KC-218/74f9f199e6d8da64f7a5c435eadc2736 to your computer and use it in GitHub Desktop.
//清除cookies
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies]){
[storage deleteCookie:cookie];
}
//清除UIWebView的缓存
[[NSURLCache sharedURLCache] removeAllCachedResponses];
NSURLCache * cache = [NSURLCache sharedURLCache];
[cache removeAllCachedResponses];
[cache setDiskCapacity:0];
[cache setMemoryCapacity:0];
[UIView setAnimationsEnabled:NO];
self.webView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:[self createWKWebApp]];
[self.view addSubview: self.webView];
[self.webView setNavigationDelegate:self];
[self.webView setUIDelegate:self];
[self.webView.configuration.preferences setValue:@YES forKey:@"allowFileAccessFromFileURLs"];
self.webView.scrollView.bounces = NO;
[self.webView setContentMode:UIViewContentModeScaleAspectFit];
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"www/engageapp"]];
if (@available(iOS 11.0, *)) { //適配IphoneX機型
self.webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
NSURLRequest *request = [NSURLRequest requestWithURL:url];
self.globalRequestForIos11 = request;
[self.webView loadRequest:request];
} else {
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:180];
[request setHTTPMethod:@"POST"];
self.globalRequest = request;
[self.webView loadRequest:request];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment