Skip to content

Instantly share code, notes, and snippets.

@lihei12345
Created March 29, 2016 12:13
Show Gist options
  • Save lihei12345/134610249b33af887202 to your computer and use it in GitHub Desktop.
Save lihei12345/134610249b33af887202 to your computer and use it in GitHub Desktop.
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
{
WKNavigationActionPolicy policy = WKNavigationActionPolicyAllow;
BOOL isFragmentJump = NO;
if (navigationAction.request.URL.fragment) {
NSString *nonFragmentURL = [navigationAction.request.URL wm_nonFragmentURLString];
isFragmentJump = [nonFragmentURL isEqualToString:webView.URL.absoluteString];
}
if (!isFragmentJump) {
BOOL should = [_webViewDelegate wmWebView:self shouldStartLoadWithRequest:navigationAction.request];
if (!should) {
decisionHandler(WKNavigationActionPolicyCancel);
return;
}
}
if ((policy == WKNavigationActionPolicyAllow) && !isFragmentJump && [navigationAction.request.URL wm_isHTTPOrFileURL]) {
_lastRequest = [navigationAction.request mutableCopy];
}
decisionHandler(policy);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment