-
Notifications
You must be signed in to change notification settings - Fork 29
/
NSURLProtocol+WKWebViewSupport.m
52 lines (44 loc) · 1.29 KB
/
NSURLProtocol+WKWebViewSupport.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// NSURLProtocol+WKWebViewSupport.m
// Pods
//
// Created by Dylan on 2016/11/14.
//
//
#import "NSURLProtocol+WKWebViewSupport.h"
#import <WebKit/WebKit.h>
Class WK_ContextControllerClass() {
static Class cls;
if (!cls) {
cls = [[[WKWebView new] valueForKey:@"browsingContextController"] class];
}
return cls;
}
SEL WK_RegisterSchemeSelector() {
return NSSelectorFromString(@"registerSchemeForCustomProtocol:");
}
SEL WK_UnregisterSchemeSelector() {
return NSSelectorFromString(@"unregisterSchemeForCustomProtocol:");
}
@implementation NSURLProtocol (WKWebViewSupport)
+ (void)wk_registerScheme:(NSString *)scheme {
Class cls = WK_ContextControllerClass();
SEL sel = WK_RegisterSchemeSelector();
if ([(id)cls respondsToSelector:sel]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[(id)cls performSelector:sel withObject:scheme];
#pragma clang diagnostic pop
}
}
+ (void)wk_unregisterScheme:(NSString *)scheme {
Class cls = WK_ContextControllerClass();
SEL sel = WK_UnregisterSchemeSelector();
if ([(id)cls respondsToSelector:sel]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[(id)cls performSelector:sel withObject:scheme];
#pragma clang diagnostic pop
}
}
@end