| | |
| | | // |
| | | |
| | | #import "SettingWebView.h" |
| | | #import <WebKit/WebKit.h> |
| | | #import "dsbridge.h" |
| | | #import "JSAPI.h" |
| | | |
| | | @interface SettingWebView () |
| | | |
| | | @property (nonatomic, nullable, strong) DWKWebView *webView; |
| | | |
| | | @end |
| | | |
| | |
| | | height = 84; |
| | | } |
| | | |
| | | WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, KScreenH - height)]; |
| | | [self.view addSubview: webView]; |
| | | // WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, KScreenH - height)]; |
| | | [self.view addSubview: self.webView]; |
| | | [self.webView addJavascriptObject:[[JSAPI alloc] init] namespace:@"yestv"]; |
| | | NSURLRequest *request =[NSURLRequest requestWithURL:[NSURL URLWithString:_requestURL]]; |
| | | [webView loadRequest:request]; |
| | | [_webView loadRequest:request]; |
| | | // Do any additional setup after loading the view from its nib. |
| | | } |
| | | |
| | | |
| | | - (DWKWebView *)webView { |
| | | if (!_webView) { |
| | | // 0.网页配置对象 |
| | | WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init]; |
| | | // 1.原生与JS交互管理 |
| | | WKUserContentController *userContentController = [[WKUserContentController alloc] init]; |
| | | |
| | | // 添加 |
| | | config.userContentController = userContentController; |
| | | |
| | | // 3.WKWebview设置 |
| | | WKPreferences *prefer = [[WKPreferences alloc] init]; |
| | | //设置是否支持javaScript 默认是支持的 |
| | | prefer.javaScriptEnabled = YES; |
| | | // // 在iOS上默认为NO,表示是否允许不经过用户交互由javaScript自动打开窗口 |
| | | prefer.javaScriptCanOpenWindowsAutomatically = YES; |
| | | // 添加 |
| | | config.preferences = prefer; |
| | | config.preferences.minimumFontSize = 0.0f; |
| | | // 是使用h5的视频播放器在线播放, 还是使用原生播放器全屏播放 |
| | | config.allowsInlineMediaPlayback = YES; |
| | | //设置视频是否需要用户手动播放 设置为NO则会允许自动播放 |
| | | config.mediaTypesRequiringUserActionForPlayback = YES; |
| | | //设置是否允许画中画技术 在特定设备上有效 |
| | | config.allowsPictureInPictureMediaPlayback = YES; |
| | | //设置请求的User-Agent信息中应用程序名称 iOS9后可用 |
| | | config.applicationNameForUserAgent = @"ChinaDailyForiPad"; |
| | | |
| | | config.suppressesIncrementalRendering = YES; |
| | | |
| | | CGFloat height = 64; |
| | | if (KIsiPhoneX) { |
| | | height = 84; |
| | | } |
| | | |
| | | _webView = [[DWKWebView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, KScreenH - height) configuration:config]; |
| | | |
| | | _webView.DSUIDelegate = self; |
| | | _webView.navigationDelegate = self; |
| | | |
| | | // 是否允许手势左滑返回上一级, 类似导航控制的左滑返回 |
| | | _webView.allowsBackForwardNavigationGestures = YES; |
| | | //可返回的页面列表, 存储已打开过的网页 |
| | | //WKBackForwardList * backForwardList = [_webView backForwardList]; |
| | | } |
| | | return _webView; |
| | | } |
| | | |
| | | -(void)presentBack{ |
| | | [self dismissViewControllerAnimated:YES completion:^{ |
| | | //状态栏重现 |
| | |
| | | } |
| | | |
| | | -(void)back:(id)sender{ |
| | | if(_webView!=nil){ |
| | | if([_webView canGoBack]){ |
| | | [_webView goBack]; |
| | | return; |
| | | } |
| | | } |
| | | [self.navigationController popViewControllerAnimated:YES]; |
| | | } |
| | | |