mirror of
https://github.com/leanote/leanote-ios.git
synced 2026-01-14 06:05:02 +08:00
Update AFNetworking to 4.0 NSURLProtocol+WebKitSupport.h for WKWebView https://github.com/Yeatse/NSURLProtocol-WebKitSupport
57 lines
1.5 KiB
Objective-C
57 lines
1.5 KiB
Objective-C
//
|
|
// NSURLProtocol+WebKitSupport.m
|
|
// NSURLProtocol+WebKitSupport
|
|
//
|
|
// Created by yeatse on 2016/10/11.
|
|
// Copyright © 2016年 Yeatse. All rights reserved.
|
|
//
|
|
|
|
#import "NSURLProtocol+WebKitSupport.h"
|
|
#import <WebKit/WebKit.h>
|
|
|
|
/**
|
|
* The functions below use some undocumented APIs, which may lead to rejection by Apple.
|
|
*/
|
|
|
|
FOUNDATION_STATIC_INLINE Class ContextControllerClass() {
|
|
static Class cls;
|
|
if (!cls) {
|
|
cls = [[[WKWebView new] valueForKey:@"browsingContextController"] class];
|
|
}
|
|
return cls;
|
|
}
|
|
|
|
FOUNDATION_STATIC_INLINE SEL RegisterSchemeSelector() {
|
|
return NSSelectorFromString(@"registerSchemeForCustomProtocol:");
|
|
}
|
|
|
|
FOUNDATION_STATIC_INLINE SEL UnregisterSchemeSelector() {
|
|
return NSSelectorFromString(@"unregisterSchemeForCustomProtocol:");
|
|
}
|
|
|
|
@implementation NSURLProtocol (WebKitSupport)
|
|
|
|
+ (void)wk_registerScheme:(NSString *)scheme {
|
|
Class cls = ContextControllerClass();
|
|
SEL sel = 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 = ContextControllerClass();
|
|
SEL sel = 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
|