#if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_8_0

时间:2021-09-30 23:24:46

头文件处理

#import <UIKit/UIKit.h>
#if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_8_0
#else
#import <WebKit/WebKit.h>
#endif

属性处理

@interface AdaptiveWebView ()<UIWebViewDelegate,WKNavigationDelegate>
#if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_8_0
@property WebViewJavascriptBridge* bridge;
#else
@property WKWebViewJavascriptBridge *bridge;
#endif
@end

代码处理

-(void)setUrl:(NSString *)url{
_url = url;
NSURLRequest *urlRequest = [[NSURLRequest alloc]initWithURL:[NSURL URLWithString:url]]; #if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_8_0
[self.webView loadRequest:urlRequest];
_bridge = [WebViewJavascriptBridge bridgeForWebView:self.webView];
[_bridge setWebViewDelegate:self];
#else
[self.wkWebView loadRequest:urlRequest];
_bridge = [WKWebViewJavascriptBridge bridgeForWebView:self.wkWebView];
[_bridge setWebViewDelegate:self];
#endif
@WeakObj(self)