如何取消对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"];
    }
发布了120 篇原创文章 · 获赞 15 · 访问量 17万+

猜你喜欢

转载自blog.csdn.net/qq_15509071/article/details/89398355