如何取消对WKWebView的请求拦截

 

使用unregisterSchemeForCustomProtocol取消拦截

 

    [NSURLProtocol unregisterClass:[MyURLProtocol class]];

    Class cls = NSClassFromString(@"WKBrowsingContextController");
    SEL sel = NSSelectorFromString(@"unregisterSchemeForCustomProtocol:");
    if ([(id)cls respondsToSelector:sel]) {
        [(id)cls performSelector:sel withObject:@"http"];
        [(id)cls performSelector:sel withObject:@"https"];
    }

 

 

需要拦截的时候再

    [NSURLProtocol registerClass:[MyURLProtocol class]];

    Class cls = NSClassFromString(@"WKBrowsingContextController");
    SEL sel = NSSelectorFromString(@"registerSchemeForCustomProtocol:");
    if ([(id)cls respondsToSelector:sel]) {
        [(id)cls performSelector:sel withObject:@"http"];
        [(id)cls performSelector:sel withObject:@"https"];
    }

 

你可能感兴趣的:(ios)