Commit a9ba6408f798d4275988de9ea4a0ebff4a20dc64

Authored by zhangxiaowen
1 parent 9908d894

no message

CNLiveUserAgreementManager.podspec
@@ -38,7 +38,8 @@ TODO: Add long description of the pod here. @@ -38,7 +38,8 @@ TODO: Add long description of the pod here.
38 38
39 s.public_header_files = 'CNLiveUserAgreementManager/Classes/**/*.h' 39 s.public_header_files = 'CNLiveUserAgreementManager/Classes/**/*.h'
40 # s.frameworks = 'UIKit', 'MapKit' 40 # s.frameworks = 'UIKit', 'MapKit'
41 - # s.dependency 'AFNetworking', '~> 2.3' 41 + #
  42 + s.dependency 'WebViewJavascriptBridge'
42 s.dependency 'CNLiveRequestBastKit' 43 s.dependency 'CNLiveRequestBastKit'
43 s.dependency 'CNLiveEnvironment' 44 s.dependency 'CNLiveEnvironment'
44 45
CNLiveUserAgreementManager/Classes/CNLiveAgreementManager.h
@@ -9,7 +9,8 @@ @@ -9,7 +9,8 @@
9 #import <Foundation/Foundation.h> 9 #import <Foundation/Foundation.h>
10 10
11 NS_ASSUME_NONNULL_BEGIN 11 NS_ASSUME_NONNULL_BEGIN
12 -typedef enum { 12 +
  13 +typedef NS_ENUM(NSUInteger, CNGetAgreementH5Type) {
13 CNAgreementUser = 1001,//用户协议 14 CNAgreementUser = 1001,//用户协议
14 CNAgreementPrivacy = 1002,//隐私政策 15 CNAgreementPrivacy = 1002,//隐私政策
15 CNAgreementHelp = 1003,//帮助与反馈 16 CNAgreementHelp = 1003,//帮助与反馈
@@ -24,11 +25,11 @@ typedef enum { @@ -24,11 +25,11 @@ typedef enum {
24 CNAgreementEmojiService = 1012,//表情包服务说明 25 CNAgreementEmojiService = 1012,//表情包服务说明
25 CNAgreementEmojiComplaints = 1013,//表情包投诉说明 26 CNAgreementEmojiComplaints = 1013,//表情包投诉说明
26 CNAgreementEnterpriseQualification = 1014,//企业资质 27 CNAgreementEnterpriseQualification = 1014,//企业资质
27 - CNAgreementBuyAudio = 1015,//购买音频协议 28 + CNAgreementBuyAudio = 1015 //购买音频协议
28 29
29 -} CNGetAgreementH5Type; 30 +};
30 31
31 -typedef void(^SuccessBlock)(NSString *h5, NSString *title); 32 +typedef void(^SuccessBlock)(NSString *h5, NSString *title, BOOL isShow);
32 typedef void(^FailureBlock)(NSError *error); 33 typedef void(^FailureBlock)(NSError *error);
33 34
34 @interface CNLiveAgreementManager : NSObject 35 @interface CNLiveAgreementManager : NSObject
CNLiveUserAgreementManager/Classes/CNLiveAgreementManager.m
@@ -29,7 +29,6 @@ static CNLiveAgreementManager *_instance = nil; @@ -29,7 +29,6 @@ static CNLiveAgreementManager *_instance = nil;
29 _instance = [[CNLiveAgreementManager alloc]init]; 29 _instance = [[CNLiveAgreementManager alloc]init];
30 }); 30 });
31 return _instance; 31 return _instance;
32 -  
33 } 32 }
34 33
35 + (id)allocWithZone:(struct _NSZone *)zone{ 34 + (id)allocWithZone:(struct _NSZone *)zone{
@@ -73,7 +72,7 @@ static CNLiveAgreementManager *_instance = nil; @@ -73,7 +72,7 @@ static CNLiveAgreementManager *_instance = nil;
73 { 72 {
74 if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"yhxy"]) { 73 if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"yhxy"]) {
75 if (success) { 74 if (success) {
76 - success(dic[@"detailUrl"],dic[@"title"]); 75 + success(dic[@"detailUrl"], dic[@"title"], YES);
77 return ; 76 return ;
78 } 77 }
79 } 78 }
@@ -83,7 +82,7 @@ static CNLiveAgreementManager *_instance = nil; @@ -83,7 +82,7 @@ static CNLiveAgreementManager *_instance = nil;
83 { 82 {
84 if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"yszc"]) { 83 if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"yszc"]) {
85 if (success) { 84 if (success) {
86 - success(dic[@"detailUrl"],dic[@"title"]); 85 + success(dic[@"detailUrl"], dic[@"title"], YES);
87 return ; 86 return ;
88 } 87 }
89 } 88 }
@@ -93,7 +92,7 @@ static CNLiveAgreementManager *_instance = nil; @@ -93,7 +92,7 @@ static CNLiveAgreementManager *_instance = nil;
93 { 92 {
94 if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"bzfk"]) { 93 if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"bzfk"]) {
95 if (success) { 94 if (success) {
96 - success(dic[@"detailUrl"],dic[@"title"]); 95 + success(dic[@"detailUrl"], dic[@"title"], YES);
97 return ; 96 return ;
98 } 97 }
99 } 98 }
@@ -103,7 +102,7 @@ static CNLiveAgreementManager *_instance = nil; @@ -103,7 +102,7 @@ static CNLiveAgreementManager *_instance = nil;
103 { 102 {
104 if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"ljwjj"]) { 103 if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"ljwjj"]) {
105 if (success) { 104 if (success) {
106 - success(dic[@"detailUrl"],dic[@"title"]); 105 + success(dic[@"detailUrl"], dic[@"title"], YES);
107 return ; 106 return ;
108 } 107 }
109 } 108 }
@@ -111,9 +110,9 @@ static CNLiveAgreementManager *_instance = nil; @@ -111,9 +110,9 @@ static CNLiveAgreementManager *_instance = nil;
111 break; 110 break;
112 case CNAgreementIntroduction: 111 case CNAgreementIntroduction:
113 { 112 {
114 - if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"yyjj"]) { 113 + if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"yyjj"]) {
115 if (success) { 114 if (success) {
116 - success(dic[@"detailUrl"],dic[@"title"]); 115 + success(dic[@"detailUrl"], dic[@"title"], YES);
117 return ; 116 return ;
118 } 117 }
119 } 118 }
@@ -121,9 +120,9 @@ static CNLiveAgreementManager *_instance = nil; @@ -121,9 +120,9 @@ static CNLiveAgreementManager *_instance = nil;
121 break; 120 break;
122 case CNAgreementCopyright: 121 case CNAgreementCopyright:
123 { 122 {
124 - if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"bqxx"]) { 123 + if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"bqxx"]) {
125 if (success) { 124 if (success) {
126 - success(dic[@"detailUrl"],dic[@"title"]); 125 + success(dic[@"detailUrl"], dic[@"title"], YES);
127 return ; 126 return ;
128 } 127 }
129 } 128 }
@@ -131,9 +130,9 @@ static CNLiveAgreementManager *_instance = nil; @@ -131,9 +130,9 @@ static CNLiveAgreementManager *_instance = nil;
131 break; 130 break;
132 case CNAgreementPermission: 131 case CNAgreementPermission:
133 { 132 {
134 - if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"rjxkxy"]) { 133 + if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"rjxkxy"]) {
135 if (success) { 134 if (success) {
136 - success(dic[@"detailUrl"],dic[@"title"]); 135 + success(dic[@"detailUrl"], dic[@"title"], YES);
137 return ; 136 return ;
138 } 137 }
139 } 138 }
@@ -141,9 +140,9 @@ static CNLiveAgreementManager *_instance = nil; @@ -141,9 +140,9 @@ static CNLiveAgreementManager *_instance = nil;
141 break; 140 break;
142 case CNAgreementIntegralRules: 141 case CNAgreementIntegralRules:
143 { 142 {
144 - if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"jfgz"]) { 143 + if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"jfgz"]) {
145 if (success) { 144 if (success) {
146 - success(dic[@"detailUrl"],dic[@"title"]); 145 + success(dic[@"detailUrl"], dic[@"title"], YES);
147 return ; 146 return ;
148 } 147 }
149 } 148 }
@@ -151,9 +150,9 @@ static CNLiveAgreementManager *_instance = nil; @@ -151,9 +150,9 @@ static CNLiveAgreementManager *_instance = nil;
151 break; 150 break;
152 case CNAgreementSigninRules: 151 case CNAgreementSigninRules:
153 { 152 {
154 - if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"jfjlgz"]) { 153 + if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"jfjlgz"]) {
155 if (success) { 154 if (success) {
156 - success(dic[@"detailUrl"],dic[@"title"]); 155 + success(dic[@"detailUrl"], dic[@"title"], YES);
157 return ; 156 return ;
158 } 157 }
159 } 158 }
@@ -161,9 +160,9 @@ static CNLiveAgreementManager *_instance = nil; @@ -161,9 +160,9 @@ static CNLiveAgreementManager *_instance = nil;
161 break; 160 break;
162 case CNAgreementReviewApply: 161 case CNAgreementReviewApply:
163 { 162 {
164 - if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"shsqxy"]) { 163 + if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"shsqxy"]) {
165 if (success) { 164 if (success) {
166 - success(dic[@"detailUrl"],dic[@"title"]); 165 + success(dic[@"detailUrl"], dic[@"title"], YES);
167 return ; 166 return ;
168 } 167 }
169 } 168 }
@@ -171,9 +170,9 @@ static CNLiveAgreementManager *_instance = nil; @@ -171,9 +170,9 @@ static CNLiveAgreementManager *_instance = nil;
171 break; 170 break;
172 case CNAgreementCancellation: 171 case CNAgreementCancellation:
173 { 172 {
174 - if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"zxxz"]) { 173 + if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"zxxz"]) {
175 if (success) { 174 if (success) {
176 - success(dic[@"detailUrl"],dic[@"title"]); 175 + success(dic[@"detailUrl"], dic[@"title"], YES);
177 return ; 176 return ;
178 } 177 }
179 } 178 }
@@ -181,9 +180,9 @@ static CNLiveAgreementManager *_instance = nil; @@ -181,9 +180,9 @@ static CNLiveAgreementManager *_instance = nil;
181 break; 180 break;
182 case CNAgreementEmojiService: 181 case CNAgreementEmojiService:
183 { 182 {
184 - if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"fwsm"]) { 183 + if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"fwsm"]) {
185 if (success) { 184 if (success) {
186 - success(dic[@"detailUrl"],dic[@"title"]); 185 + success(dic[@"detailUrl"], dic[@"title"], YES);
187 return ; 186 return ;
188 } 187 }
189 } 188 }
@@ -191,9 +190,9 @@ static CNLiveAgreementManager *_instance = nil; @@ -191,9 +190,9 @@ static CNLiveAgreementManager *_instance = nil;
191 break; 190 break;
192 case CNAgreementEmojiComplaints: 191 case CNAgreementEmojiComplaints:
193 { 192 {
194 - if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"tssm"]) { 193 + if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"tssm"]) {
195 if (success) { 194 if (success) {
196 - success(dic[@"detailUrl"],dic[@"title"]); 195 + success(dic[@"detailUrl"], dic[@"title"], YES);
197 return ; 196 return ;
198 } 197 }
199 } 198 }
@@ -201,9 +200,9 @@ static CNLiveAgreementManager *_instance = nil; @@ -201,9 +200,9 @@ static CNLiveAgreementManager *_instance = nil;
201 break; 200 break;
202 case CNAgreementEnterpriseQualification: 201 case CNAgreementEnterpriseQualification:
203 { 202 {
204 - if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"qyzz"]) { 203 + if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"qyzz"]) {
205 if (success) { 204 if (success) {
206 - success(dic[@"detailUrl"],dic[@"title"]); 205 + success(dic[@"detailUrl"], dic[@"title"], YES);
207 return ; 206 return ;
208 } 207 }
209 } 208 }
@@ -211,9 +210,9 @@ static CNLiveAgreementManager *_instance = nil; @@ -211,9 +210,9 @@ static CNLiveAgreementManager *_instance = nil;
211 break; 210 break;
212 case CNAgreementBuyAudio: 211 case CNAgreementBuyAudio:
213 { 212 {
214 - if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"ypxy"]) { 213 + if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"ypxy"]) {
215 if (success) { 214 if (success) {
216 - success(dic[@"detailUrl"],dic[@"title"]); 215 + success(dic[@"detailUrl"], dic[@"title"], YES);
217 return ; 216 return ;
218 } 217 }
219 } 218 }
@@ -241,8 +240,8 @@ static CNLiveAgreementManager *_instance = nil; @@ -241,8 +240,8 @@ static CNLiveAgreementManager *_instance = nil;
241 * @param failure 请求失败回调 240 * @param failure 请求失败回调
242 */ 241 */
243 + (void)getAgreementH5WithType:(CNGetAgreementH5Type)type success:(SuccessBlock)success failure:(FailureBlock)failure { 242 + (void)getAgreementH5WithType:(CNGetAgreementH5Type)type success:(SuccessBlock)success failure:(FailureBlock)failure {
244 - [[CNLiveAgreementManager manager] getAgreementH5WithType:type success:^(NSString * _Nonnull h5, NSString * _Nonnull title) {  
245 - success?success(h5, title):@""; 243 + [[CNLiveAgreementManager manager] getAgreementH5WithType:type success:^(NSString * _Nonnull h5, NSString * _Nonnull title, BOOL isShow) {
  244 + success?success(h5, title, isShow):@"";
246 245
247 } failure:^(NSError * _Nonnull error) { 246 } failure:^(NSError * _Nonnull error) {
248 failure?failure(error):@""; 247 failure?failure(error):@"";
@@ -257,10 +256,10 @@ static CNLiveAgreementManager *_instance = nil; @@ -257,10 +256,10 @@ static CNLiveAgreementManager *_instance = nil;
257 */ 256 */
258 + (void)jumpToAgreementH5WithType:(CNGetAgreementH5Type)type{ 257 + (void)jumpToAgreementH5WithType:(CNGetAgreementH5Type)type{
259 __weak typeof(self) weakSelf = self; 258 __weak typeof(self) weakSelf = self;
260 - [CNLiveAgreementManager getAgreementH5WithType:type success:^(NSString *h5, NSString *title) { 259 + [CNLiveAgreementManager getAgreementH5WithType:type success:^(NSString *h5, NSString *title, BOOL isShow) {
261 __strong typeof(weakSelf) strongSelf = weakSelf; 260 __strong typeof(weakSelf) strongSelf = weakSelf;
262 if(!strongSelf) return; 261 if(!strongSelf) return;
263 - [strongSelf pushToWebControllerUrl:h5 name:title showCloseBtn:YES]; 262 + [strongSelf pushToWebControllerUrl:h5 name:title showCloseBtn:isShow];
264 263
265 } failure:^(NSError *error) { 264 } failure:^(NSError *error) {
266 if(TestEnvironment){ 265 if(TestEnvironment){
@@ -278,10 +277,10 @@ static CNLiveAgreementManager *_instance = nil; @@ -278,10 +277,10 @@ static CNLiveAgreementManager *_instance = nil;
278 */ 277 */
279 + (void)jumpToAgreementH5WithString:(NSString *)string { 278 + (void)jumpToAgreementH5WithString:(NSString *)string {
280 __weak typeof(self) weakSelf = self; 279 __weak typeof(self) weakSelf = self;
281 - [CNLiveAgreementManager getAgreementH5WithString:string success:^(NSString *h5, NSString *title) { 280 + [CNLiveAgreementManager getAgreementH5WithString:string success:^(NSString *h5, NSString *title, BOOL isShow) {
282 __strong typeof(weakSelf) strongSelf = weakSelf; 281 __strong typeof(weakSelf) strongSelf = weakSelf;
283 if(!strongSelf) return; 282 if(!strongSelf) return;
284 - [strongSelf pushToWebControllerUrl:h5 name:title showCloseBtn:NO]; 283 + [strongSelf pushToWebControllerUrl:h5 name:title showCloseBtn:isShow];
285 284
286 } failure:^(NSError *error) { 285 } failure:^(NSError *error) {
287 if(TestEnvironment){ 286 if(TestEnvironment){
@@ -299,8 +298,8 @@ static CNLiveAgreementManager *_instance = nil; @@ -299,8 +298,8 @@ static CNLiveAgreementManager *_instance = nil;
299 * @param failure 请求失败回调 298 * @param failure 请求失败回调
300 */ 299 */
301 + (void)getAgreementH5WithString:(NSString *)string success:(SuccessBlock)success failure:(FailureBlock)failure{ 300 + (void)getAgreementH5WithString:(NSString *)string success:(SuccessBlock)success failure:(FailureBlock)failure{
302 - [[CNLiveAgreementManager manager] getAgreementH5WithString:string success:^(NSString *h5, NSString *title) {  
303 - success?success(h5, title):@""; 301 + [[CNLiveAgreementManager manager] getAgreementH5WithString:string success:^(NSString *h5, NSString *title, BOOL isShow) {
  302 + success?success(h5, title, isShow):@"";
304 303
305 } failure:^(NSError *error) { 304 } failure:^(NSError *error) {
306 failure?failure(error):@""; 305 failure?failure(error):@"";
@@ -321,7 +320,7 @@ static CNLiveAgreementManager *_instance = nil; @@ -321,7 +320,7 @@ static CNLiveAgreementManager *_instance = nil;
321 if ([responseObject isKindOfClass:[NSArray class]]) { 320 if ([responseObject isKindOfClass:[NSArray class]]) {
322 for (NSDictionary *dic in responseObject) { 321 for (NSDictionary *dic in responseObject) {
323 if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:string]) { 322 if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:string]) {
324 - success?success(dic[@"detailUrl"], dic[@"title"]):@""; 323 + success?success(dic[@"detailUrl"], dic[@"title"], YES):@"";
325 return; 324 return;
326 } 325 }
327 326
CNLiveUserAgreementManager/Classes/CNLiveAgreementWebController.h
@@ -17,7 +17,7 @@ NS_ASSUME_NONNULL_BEGIN @@ -17,7 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
17 * @param name 标题 17 * @param name 标题
18 * @param isShow 是否显示关闭按钮 18 * @param isShow 是否显示关闭按钮
19 */ 19 */
20 -- (instancetype)initWithUrl:(NSString *)url name:(NSString *)name showCloseBtn:(BOOL)isShow; 20 +- (instancetype)initWithUrl:(NSString *)url name:(nullable NSString *)name showCloseBtn:(BOOL)isShow;
21 21
22 @end 22 @end
23 23
CNLiveUserAgreementManager/Classes/CNLiveAgreementWebController.m
@@ -7,13 +7,16 @@ @@ -7,13 +7,16 @@
7 // 7 //
8 8
9 #import "CNLiveAgreementWebController.h" 9 #import "CNLiveAgreementWebController.h"
  10 +#import "WKWebViewJavascriptBridge.h"
10 #import <WebKit/WebKit.h> 11 #import <WebKit/WebKit.h>
  12 +#import "CNLiveEnvironment.h"
11 13
12 @interface CNLiveAgreementWebController ()<WKUIDelegate, WKNavigationDelegate> 14 @interface CNLiveAgreementWebController ()<WKUIDelegate, WKNavigationDelegate>
13 @property (nonatomic, copy) NSString *url; 15 @property (nonatomic, copy) NSString *url;
14 @property (nonatomic, copy) NSString *name; 16 @property (nonatomic, copy) NSString *name;
15 @property (nonatomic, assign) BOOL isShow; 17 @property (nonatomic, assign) BOOL isShow;
16 18
  19 +@property (nonatomic, strong) WKWebViewJavascriptBridge *bridge;
17 @property (nonatomic, strong) WKWebView *webView; 20 @property (nonatomic, strong) WKWebView *webView;
18 @property (nonatomic, strong) UIProgressView *processView; 21 @property (nonatomic, strong) UIProgressView *processView;
19 @property (nonatomic, weak) UILabel *titleLabel; 22 @property (nonatomic, weak) UILabel *titleLabel;
@@ -21,8 +24,8 @@ @@ -21,8 +24,8 @@
21 @end 24 @end
22 25
23 @implementation CNLiveAgreementWebController 26 @implementation CNLiveAgreementWebController
24 -  
25 -- (instancetype)initWithUrl:(NSString *)url name:(NSString *)name showCloseBtn:(BOOL)isShow { 27 +#pragma mark - 初始化方法
  28 +- (instancetype)initWithUrl:(NSString *)url name:(nullable NSString *)name showCloseBtn:(BOOL)isShow {
26 self = [super init]; 29 self = [super init];
27 if (self) { 30 if (self) {
28 self.url = url; 31 self.url = url;
@@ -69,12 +72,17 @@ @@ -69,12 +72,17 @@
69 } 72 }
70 [self setupNavigationBar]; 73 [self setupNavigationBar];
71 [self setupUI]; 74 [self setupUI];
  75 + [self setupUserAgent];
  76 + [self interaction];
72 [self loadUrl]; 77 [self loadUrl];
73 78
74 } 79 }
75 80
76 - (void)dealloc { 81 - (void)dealloc {
77 - NSLog(@"CNUserAgreementWebController dealloc"); 82 + if(TestEnvironment){
  83 + NSLog(@"CNUserAgreementWebController dealloc");
  84 +
  85 + }
78 [self.webView stopLoading]; 86 [self.webView stopLoading];
79 [self.webView removeObserver:self forKeyPath:@"estimatedProgress"]; 87 [self.webView removeObserver:self forKeyPath:@"estimatedProgress"];
80 if (!self.name) { 88 if (!self.name) {
@@ -87,6 +95,107 @@ @@ -87,6 +95,107 @@
87 95
88 } 96 }
89 97
  98 +#pragma mark - 交互相关
  99 +- (void)interaction {
  100 + [WKWebViewJavascriptBridge enableLogging];
  101 + self.bridge = [WKWebViewJavascriptBridge bridgeForWebView:self.webView];
  102 + [self.bridge setWebViewDelegate:self];
  103 +
  104 + __weak typeof(self) weakSelf = self;
  105 +
  106 + // 帮助与反馈->产品建议:添加照片按钮
  107 + [self.bridge registerHandler:@"wjjHelpAndFeedbackImage" handler:^(id data, WVJBResponseCallback responseCallback) {
  108 + if(TestEnvironment){
  109 + NSLog(@"ObjC Echo called with: %@", data);
  110 +
  111 + }
  112 + __strong typeof(weakSelf) strongSelf = weakSelf;
  113 + if(strongSelf){
  114 +
  115 + }
  116 + responseCallback(data);
  117 + }];
  118 +
  119 + // 帮助与反馈->产品建议:删除照片
  120 + [self.bridge registerHandler:@"wjjDelegateImage" handler:^(id data, WVJBResponseCallback responseCallback) {
  121 + if(TestEnvironment){
  122 + NSLog(@"ObjC Echo called with: %@", data);
  123 +
  124 + }
  125 + __strong typeof(weakSelf) strongSelf = weakSelf;
  126 + if(strongSelf){
  127 +
  128 + }
  129 + responseCallback(data);
  130 + }];
  131 +
  132 + // 帮助与反馈->产品建议:点击提交
  133 + [self.bridge registerHandler:@"wjjSubmitImage" handler:^(id data, WVJBResponseCallback responseCallback) {
  134 + if(TestEnvironment){
  135 + NSLog(@"ObjC Echo called with: %@", data);
  136 +
  137 + }
  138 + __strong typeof(weakSelf) strongSelf = weakSelf;
  139 + if(strongSelf){
  140 +
  141 + }
  142 + responseCallback(data);
  143 + }];
  144 +
  145 + // 反馈提交(成功/失败)后隐藏loading
  146 + [self.bridge registerHandler:@"wjjSubmitSuccessFinal" handler:^(id data, WVJBResponseCallback responseCallback) {
  147 + if(TestEnvironment){
  148 + NSLog(@"ObjC Echo called with: %@", data);
  149 +
  150 + }
  151 + __strong typeof(weakSelf) strongSelf = weakSelf;
  152 + if(strongSelf){
  153 +
  154 + }
  155 + responseCallback(data);
  156 + }];
  157 +
  158 + // 帮助与反馈 提交反馈后点击完成
  159 + [self.bridge registerHandler:@"wjjFeedbackSuccess" handler:^(id data, WVJBResponseCallback responseCallback) {
  160 + if(TestEnvironment){
  161 + NSLog(@"ObjC Echo called with: %@", data);
  162 +
  163 + }
  164 + __strong typeof(weakSelf) strongSelf = weakSelf;
  165 + if(strongSelf){
  166 +
  167 + }
  168 + responseCallback(data);
  169 + }];
  170 +
  171 + // h5主动从客户端获取网络状态
  172 + [self.bridge registerHandler:@"wjjJSGetNetStatusFromClient" handler:^(id data, WVJBResponseCallback responseCallback) {
  173 + if(TestEnvironment){
  174 + NSLog(@"ObjC Echo called with: %@", data);
  175 +
  176 + }
  177 + __strong typeof(weakSelf) strongSelf = weakSelf;
  178 + if(strongSelf){
  179 +
  180 + }
  181 + responseCallback(data);
  182 + }];
  183 +
  184 + // 原生直播/回放无网络时的提示
  185 + [self.bridge registerHandler:@"wjjClickLiveOnLine" handler:^(id data, WVJBResponseCallback responseCallback) {
  186 + if(TestEnvironment){
  187 + NSLog(@"ObjC Echo called with: %@", data);
  188 +
  189 + }
  190 + __strong typeof(weakSelf) strongSelf = weakSelf;
  191 + if(strongSelf){
  192 +
  193 + }
  194 + responseCallback(data);
  195 + }];
  196 +
  197 +}
  198 +
90 #pragma mark - 创建导航条 199 #pragma mark - 创建导航条
91 - (void)setupNavigationBar { 200 - (void)setupNavigationBar {
92 UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, [UIApplication sharedApplication].statusBarFrame.size.height, [UIScreen mainScreen].bounds.size.width, 44)]; 201 UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, [UIApplication sharedApplication].statusBarFrame.size.height, [UIScreen mainScreen].bounds.size.width, 44)];
@@ -135,15 +244,41 @@ @@ -135,15 +244,41 @@
135 [self.view addSubview:self.webView]; 244 [self.view addSubview:self.webView];
136 245
137 self.processView = [[UIProgressView alloc] initWithFrame:CGRectMake(0, ([UIApplication sharedApplication].statusBarFrame.size.height+44)+0.5, [[UIScreen mainScreen] bounds].size.width, 1)]; 246 self.processView = [[UIProgressView alloc] initWithFrame:CGRectMake(0, ([UIApplication sharedApplication].statusBarFrame.size.height+44)+0.5, [[UIScreen mainScreen] bounds].size.width, 1)];
138 - _processView.progressTintColor = [UIColor colorWithRed:0.0 green:1.0 blue:0.0 alpha:1.0]; 247 + _processView.progressTintColor = [UIColor colorWithRed:19/255.0 green:204/255.0 blue:12/255.0 alpha:1.0];
139 _processView.trackTintColor = [UIColor whiteColor]; 248 _processView.trackTintColor = [UIColor whiteColor];
140 [self.view addSubview:self.processView]; 249 [self.view addSubview:self.processView];
141 250
  251 +}
  252 +
  253 +- (void)setupUserAgent {
  254 + NSString *customUserAgent = @";app/plat_a";
  255 +
  256 + if (@available(iOS 12.0, *)) {
  257 + UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero];
  258 + NSString *userAgent = [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
  259 + NSString *newUserAgent = [userAgent stringByAppendingString:customUserAgent];//自定义需要拼接的字符串
  260 + NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:newUserAgent, @"UserAgent", nil];
  261 +
  262 + [self.webView setCustomUserAgent:newUserAgent];
  263 + [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
  264 + }
  265 +
  266 + __weak typeof(self) weakSelf = self;
  267 + [self.webView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id result, NSError *error) {
  268 + __strong typeof(weakSelf) strongSelf = weakSelf;
  269 + NSString *userAgent = result;
  270 + NSString *newUserAgent = [userAgent stringByAppendingString:customUserAgent];
  271 + NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:newUserAgent, @"UserAgent", nil];
  272 + [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
  273 + if (@available(iOS 9.0, *)) {
  274 + [strongSelf.webView setCustomUserAgent:newUserAgent];
  275 + }
  276 + }];
  277 +
142 [self.webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil]; 278 [self.webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
143 if (!self.name) { 279 if (!self.name) {
144 [self.webView addObserver:self forKeyPath:@"title" options:NSKeyValueObservingOptionNew context:NULL]; 280 [self.webView addObserver:self forKeyPath:@"title" options:NSKeyValueObservingOptionNew context:NULL];
145 } 281 }
146 -  
147 } 282 }
148 283
149 #pragma mark - WKNavigationDelegate 284 #pragma mark - WKNavigationDelegate
@@ -252,17 +387,18 @@ @@ -252,17 +387,18 @@
252 } 387 }
253 } 388 }
254 389
255 -#pragma mark - 清除缓存 390 +#pragma mark - 私有方法
256 // 清除缓存 391 // 清除缓存
257 - (void)clearWKCache { 392 - (void)clearWKCache {
258 NSArray *types = @[WKWebsiteDataTypeDiskCache,WKWebsiteDataTypeOfflineWebApplicationCache,WKWebsiteDataTypeMemoryCache,WKWebsiteDataTypeIndexedDBDatabases,WKWebsiteDataTypeWebSQLDatabases]; 393 NSArray *types = @[WKWebsiteDataTypeDiskCache,WKWebsiteDataTypeOfflineWebApplicationCache,WKWebsiteDataTypeMemoryCache,WKWebsiteDataTypeIndexedDBDatabases,WKWebsiteDataTypeWebSQLDatabases];
259 NSSet *websiteDataTypes = [NSSet setWithArray:types]; 394 NSSet *websiteDataTypes = [NSSet setWithArray:types];
260 NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0]; 395 NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
261 [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{ 396 [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{
262 - NSLog(@"清楚缓存完毕"); 397 +
263 }]; 398 }];
264 399
265 } 400 }
  401 +
266 /** 402 /**
267 * 创建图片 403 * 创建图片
268 * 404 *
Example/CNLiveUserAgreementManager.xcodeproj/project.pbxproj
@@ -310,6 +310,7 @@ @@ -310,6 +310,7 @@
310 "${BUILT_PRODUCTS_DIR}/CNLiveEnvironment/CNLiveEnvironment.framework", 310 "${BUILT_PRODUCTS_DIR}/CNLiveEnvironment/CNLiveEnvironment.framework",
311 "${BUILT_PRODUCTS_DIR}/CNLiveRequestBastKit/CNLiveRequestBastKit.framework", 311 "${BUILT_PRODUCTS_DIR}/CNLiveRequestBastKit/CNLiveRequestBastKit.framework",
312 "${BUILT_PRODUCTS_DIR}/CNLiveUserAgreementManager/CNLiveUserAgreementManager.framework", 312 "${BUILT_PRODUCTS_DIR}/CNLiveUserAgreementManager/CNLiveUserAgreementManager.framework",
  313 + "${BUILT_PRODUCTS_DIR}/WebViewJavascriptBridge/WebViewJavascriptBridge.framework",
313 ); 314 );
314 name = "[CP] Embed Pods Frameworks"; 315 name = "[CP] Embed Pods Frameworks";
315 outputFileListPaths = ( 316 outputFileListPaths = (
@@ -319,6 +320,7 @@ @@ -319,6 +320,7 @@
319 "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveEnvironment.framework", 320 "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveEnvironment.framework",
320 "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveRequestBastKit.framework", 321 "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveRequestBastKit.framework",
321 "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveUserAgreementManager.framework", 322 "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveUserAgreementManager.framework",
  323 + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/WebViewJavascriptBridge.framework",
322 ); 324 );
323 runOnlyForDeploymentPostprocessing = 0; 325 runOnlyForDeploymentPostprocessing = 0;
324 shellPath = /bin/sh; 326 shellPath = /bin/sh;
Example/CNLiveUserAgreementManager/CNLiveViewController.m
@@ -33,7 +33,7 @@ @@ -33,7 +33,7 @@
33 33
34 } 34 }
35 - (void)testButtonClicked { 35 - (void)testButtonClicked {
36 - [CNLiveAgreementManager jumpToAgreementH5WithType:CNAgreementUser]; 36 + [CNLiveAgreementManager jumpToAgreementH5WithType:CNAgreementHelp];
37 // [CNLiveAgreementManager jumpToAgreementH5WithString:@"yhxy"]; 37 // [CNLiveAgreementManager jumpToAgreementH5WithString:@"yhxy"];
38 38
39 } 39 }