developer
2023-05-20 c1ffd99c4b60066774eb2c97b31e4aaa014e7f51
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//
//  AboutOurViewController.m
//  PapayaPlayerDaqo
//
//  Created by weikou on 15/8/4.
//  Copyright (c) 2015年 wgj. All rights reserved.
//
 
#import "SettingWebView.h"
#import "dsbridge.h"
#import "JSAPI.h"
 
@interface SettingWebView ()
 
@property (nonatomic, nullable, strong) DWKWebView *webView;
 
@end
 
@implementation SettingWebView
 
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = _webTitle;
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:[[UIImage imageNamed:@"详情页面返回"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(back:)
     forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(0, 0, 32, 32);
    UIBarButtonItem *iconBarItem=[[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.leftBarButtonItem = iconBarItem;
    //设置使用模态跳转的返回按钮
    if(_ispresent){
        //隐藏状态栏
        [[UIApplication sharedApplication] setStatusBarHidden:YES];
        //添加返回按钮
        CGFloat height = 15;
        if (KIsiPhoneX) {
            height = 35;   
        }
        UIButton *backButton=[[UIButton alloc] initWithFrame:CGRectMake(15, height, 32, 32)];
        [backButton setImage:[UIImage imageNamed:@"取消登录"] forState:UIControlStateNormal];
        [backButton addTarget:self action:@selector(presentBack) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:backButton];
    }
    CGFloat height = 64;
    if (KIsiPhoneX) {
        height = 84;
    }
    
//    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];
    // 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:^{
        //状态栏重现
        [[UIApplication sharedApplication] setStatusBarHidden:NO];
    }];
}
 
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
 
-(void)back:(id)sender{
    if(_webView!=nil){
        if([_webView canGoBack]){
            [_webView goBack];
            return;
        }
    }
    [self.navigationController popViewControllerAnimated:YES];
}
 
/*
#pragma mark - Navigation
 
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
 
@end