Commit 2e7ab86af6f43b247e782fb50ae1152996c948a7

Authored by zhangxiaowen
1 parent 5f621a7e

no message

Showing 15 changed files with 443 additions and 672 deletions
CNLiveUserAgreementManager.podspec
@@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
9 Pod::Spec.new do |s| 9 Pod::Spec.new do |s|
10 s.name = 'CNLiveUserAgreementManager' 10 s.name = 'CNLiveUserAgreementManager'
11 s.version = '0.0.1' 11 s.version = '0.0.1'
12 - s.summary = '网家家用户协议管理类' 12 + s.summary = 'CNLiveUserAgreementManager'
13 13
14 # This description is used to generate tags and improve search results. 14 # This description is used to generate tags and improve search results.
15 # * Think: What does it do? Why did you write it? What is the focus? 15 # * Think: What does it do? Why did you write it? What is the focus?
@@ -18,7 +18,7 @@ Pod::Spec.new do |s| @@ -18,7 +18,7 @@ Pod::Spec.new do |s|
18 # * Finally, don't worry about the indent, CocoaPods strips it! 18 # * Finally, don't worry about the indent, CocoaPods strips it!
19 19
20 s.description = <<-DESC 20 s.description = <<-DESC
21 -TODO: Add long description of the pod here. 21 +TODO: 网家家-用户协议管理类.
22 DESC 22 DESC
23 23
24 s.homepage = 'http://bj.gitlab.cnlive.com/ios-team/CNLiveUserAgreementManager' 24 s.homepage = 'http://bj.gitlab.cnlive.com/ios-team/CNLiveUserAgreementManager'
@@ -33,16 +33,26 @@ TODO: Add long description of the pod here. @@ -33,16 +33,26 @@ TODO: Add long description of the pod here.
33 s.source_files = 'CNLiveUserAgreementManager/Classes/**/*' 33 s.source_files = 'CNLiveUserAgreementManager/Classes/**/*'
34 34
35 s.resource_bundles = { 35 s.resource_bundles = {
36 - 'CNLiveAgreementManager' => ['CNLiveUserAgreementManager/Assets/CNLiveAgreementManager.bundle'] 36 + 'CNLiveUserAgreementManager' => ['CNLiveUserAgreementManager/Assets/CNLiveUserAgreementManager.xcassets']
37 } 37 }
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 'QMUIKit'  
42 - s.dependency 'Qiniu'  
43 - s.dependency 'WebViewJavascriptBridge'  
44 - s.dependency 'CNLiveRequestBastKit' 41 +
  42 + # pod
  43 + s.dependency 'CNLiveTripartiteManagement/QMUIKit'
  44 +
  45 + # 服务层
  46 + s.dependency 'CNLiveServices'
  47 +
  48 + #环境库
45 s.dependency 'CNLiveEnvironment' 49 s.dependency 'CNLiveEnvironment'
  50 +
  51 + # 数据请求
  52 + s.dependency 'CNLiveRequestBastKit'
  53 +
  54 + # 用户信息本地化
  55 + s.dependency 'CNLiveUserManagement'
46 56
47 57
48 end 58 end
CNLiveUserAgreementManager/Assets/CNLiveUserAgreementManager.xcassets/Contents.json 0 → 100644
  1 +{
  2 + "info" : {
  3 + "version" : 1,
  4 + "author" : "xcode"
  5 + }
  6 +}
0 \ No newline at end of file 7 \ No newline at end of file
CNLiveUserAgreementManager/Assets/CNLiveUserAgreementManager.xcassets/web_black_back.imageset/Contents.json 0 → 100644
  1 +{
  2 + "images" : [
  3 + {
  4 + "idiom" : "universal",
  5 + "scale" : "1x"
  6 + },
  7 + {
  8 + "idiom" : "universal",
  9 + "filename" : "web_black_back@2x.png",
  10 + "scale" : "2x"
  11 + },
  12 + {
  13 + "idiom" : "universal",
  14 + "filename" : "web_black_back@3x.png",
  15 + "scale" : "3x"
  16 + }
  17 + ],
  18 + "info" : {
  19 + "version" : 1,
  20 + "author" : "xcode"
  21 + }
  22 +}
0 \ No newline at end of file 23 \ No newline at end of file
CNLiveUserAgreementManager/Assets/CNLiveAgreementManager.bundle/web_black_back@2x.png renamed to CNLiveUserAgreementManager/Assets/CNLiveUserAgreementManager.xcassets/web_black_back.imageset/web_black_back@2x.png

1.49 KB

CNLiveUserAgreementManager/Assets/CNLiveAgreementManager.bundle/web_black_back@3x.png renamed to CNLiveUserAgreementManager/Assets/CNLiveUserAgreementManager.xcassets/web_black_back.imageset/web_black_back@3x.png

1.79 KB

CNLiveUserAgreementManager/Assets/CNLiveUserAgreementManager.xcassets/web_black_close.imageset/Contents.json 0 → 100644
  1 +{
  2 + "images" : [
  3 + {
  4 + "idiom" : "universal",
  5 + "scale" : "1x"
  6 + },
  7 + {
  8 + "idiom" : "universal",
  9 + "filename" : "web_black_close@2x.png",
  10 + "scale" : "2x"
  11 + },
  12 + {
  13 + "idiom" : "universal",
  14 + "filename" : "web_black_close@3x.png",
  15 + "scale" : "3x"
  16 + }
  17 + ],
  18 + "info" : {
  19 + "version" : 1,
  20 + "author" : "xcode"
  21 + }
  22 +}
0 \ No newline at end of file 23 \ No newline at end of file
CNLiveUserAgreementManager/Assets/CNLiveAgreementManager.bundle/web_black_close@2x.png renamed to CNLiveUserAgreementManager/Assets/CNLiveUserAgreementManager.xcassets/web_black_close.imageset/web_black_close@2x.png

2.92 KB

CNLiveUserAgreementManager/Assets/CNLiveAgreementManager.bundle/web_black_close@3x.png renamed to CNLiveUserAgreementManager/Assets/CNLiveUserAgreementManager.xcassets/web_black_close.imageset/web_black_close@3x.png

4.14 KB

CNLiveUserAgreementManager/Classes/CNLiveAgreementWebController.m deleted 100644 → 0
1 -//  
2 -// CNLiveAgreementWebController.m  
3 -// CNLiveServices_Example  
4 -//  
5 -// Created by CNLive-zxw on 2019/7/30.  
6 -// Copyright © 2019 153993236@qq.com. All rights reserved.  
7 -//  
8 -  
9 -#import "CNLiveAgreementWebController.h"  
10 -// 交接库  
11 -#import "WKWebViewJavascriptBridge.h"  
12 -// 七牛  
13 -#import "QiniuSDK.h"  
14 -#import <WebKit/WebKit.h>  
15 -// 环境库  
16 -#import "CNLiveEnvironment.h"  
17 -#import "QMUIKit.h"  
18 -#import <CNLiveRequestBastKit/CNLiveNetworking.h>  
19 -  
20 -@interface CNLiveAgreementWebController ()<WKUIDelegate, WKNavigationDelegate>  
21 -@property (nonatomic, copy) NSString *url;  
22 -@property (nonatomic, copy) NSString *name;  
23 -@property (nonatomic, assign) BOOL isShow;  
24 -  
25 -@property (nonatomic, strong) WKWebViewJavascriptBridge *bridge;  
26 -@property (nonatomic, strong) WKWebView *webView;  
27 -@property (nonatomic, strong) UIProgressView *processView;  
28 -@property (nonatomic, weak) UILabel *titleLabel;  
29 -  
30 -@property (nonatomic, strong) NSMutableArray *photos;// 上传图片  
31 -  
32 -@end  
33 -  
34 -@implementation CNLiveAgreementWebController  
35 -#pragma mark - 初始化方法  
36 -- (instancetype)initWithUrl:(NSString *)url name:(nullable NSString *)name showCloseBtn:(BOOL)isShow {  
37 - self = [super init];  
38 - if (self) {  
39 - self.url = url;  
40 - self.name = name;  
41 - self.isShow = isShow;  
42 - }  
43 - return self;  
44 -}  
45 -  
46 -- (void)setName:(NSString *)name{  
47 - _name = name;  
48 - _titleLabel.text = name;  
49 -  
50 -}  
51 -  
52 -#pragma mark - 加载数据  
53 -- (void)loadUrl {  
54 - NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:self.url] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:15.0];  
55 - [self.webView loadRequest:theRequest];  
56 -  
57 -}  
58 -  
59 -#pragma mark - 生命周期  
60 -- (void)viewWillAppear:(BOOL)animated {  
61 - [super viewWillAppear:animated];  
62 - self.navigationController.navigationBarHidden = YES;  
63 -  
64 -}  
65 -  
66 -- (void)viewWillDisappear:(BOOL)animated {  
67 - [super viewWillDisappear:animated];  
68 - self.navigationController.navigationBarHidden = NO;  
69 -  
70 -}  
71 -  
72 -- (void)viewDidLoad {  
73 - [super viewDidLoad];  
74 - self.view.backgroundColor = [UIColor whiteColor];  
75 - if (@available(iOS 11, *)) {  
76 - self.webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;  
77 - }  
78 - else {  
79 - self.automaticallyAdjustsScrollViewInsets = NO;  
80 - }  
81 - [self setupNavigationBar];  
82 - [self setupUI];  
83 - [self setupUserAgent];  
84 - [self interaction];  
85 - [self loadUrl];  
86 -  
87 -}  
88 -  
89 -- (void)dealloc {  
90 - if(TestEnvironment){  
91 - NSLog(@"CNUserAgreementWebController dealloc");  
92 - }  
93 - [self.webView stopLoading];  
94 - [self.webView removeObserver:self forKeyPath:@"estimatedProgress"];  
95 - if (!self.name) {  
96 - [self.webView removeObserver:self forKeyPath:@"title"];  
97 - }  
98 - self.webView.UIDelegate = nil;  
99 - self.webView.navigationDelegate = nil;  
100 - self.webView = nil;  
101 - [self clearWKCache];  
102 -  
103 -}  
104 -  
105 -#pragma mark - 交互相关  
106 -- (void)interaction {  
107 - [WKWebViewJavascriptBridge enableLogging];  
108 - self.bridge = [WKWebViewJavascriptBridge bridgeForWebView:self.webView];  
109 - [self.bridge setWebViewDelegate:self];  
110 -  
111 - __weak typeof(self) weakSelf = self;  
112 -  
113 - // 帮助与反馈->产品建议:添加照片按钮  
114 - [self.bridge registerHandler:@"wjjHelpAndFeedbackImage" handler:^(id data, WVJBResponseCallback responseCallback) {  
115 - if(TestEnvironment){  
116 - NSLog(@"ObjC Echo called with: %@", data);  
117 - }  
118 - __strong typeof(weakSelf) strongSelf = weakSelf;  
119 - if(strongSelf){  
120 -  
121 - }  
122 - responseCallback(data);  
123 - }];  
124 -  
125 - // 帮助与反馈->产品建议:删除照片  
126 - [self.bridge registerHandler:@"wjjDelegateImage" handler:^(id data, WVJBResponseCallback responseCallback) {  
127 - if(TestEnvironment){  
128 - NSLog(@"ObjC Echo called with: %@", data);  
129 - }  
130 - __strong typeof(weakSelf) strongSelf = weakSelf;  
131 - if(strongSelf){  
132 - if ([data isKindOfClass:[NSDictionary class]]) {  
133 - NSInteger index = [[data objectForKey:@"index"] integerValue];  
134 - [strongSelf.photos removeObjectAtIndex:index];  
135 - }  
136 - }  
137 - responseCallback(data);  
138 - }];  
139 -  
140 - // 帮助与反馈->产品建议:点击提交  
141 - [self.bridge registerHandler:@"wjjSubmitImage" handler:^(id data, WVJBResponseCallback responseCallback) {  
142 - if(TestEnvironment){  
143 - NSLog(@"ObjC Echo called with: %@", data);  
144 - }  
145 - __strong typeof(weakSelf) strongSelf = weakSelf;  
146 - if(strongSelf){  
147 - if (strongSelf.photos.count > 0) {  
148 - [strongSelf getImageToken];  
149 - }  
150 - else {  
151 - id data = @{ @"images": @[] };  
152 - [QMUITips showLoading:@"正在提交" inView:weakSelf.view];  
153 - // 帮助与反馈->产品建议App->h5图片urls  
154 - [strongSelf.bridge callHandler:@"wjjSubmitSuccess" data:data responseCallback:^(id responseData) {  
155 - if(TestEnvironment){  
156 - NSLog(@"ObjC received response: %@", responseData);  
157 - }  
158 - }];  
159 - }  
160 -  
161 - }  
162 - responseCallback(data);  
163 - }];  
164 -  
165 - // 反馈提交(成功/失败)后隐藏loading  
166 - [self.bridge registerHandler:@"wjjSubmitSuccessFinal" handler:^(id data, WVJBResponseCallback responseCallback) {  
167 - if(TestEnvironment){  
168 - NSLog(@"ObjC Echo called with: %@", data);  
169 - }  
170 - __strong typeof(weakSelf) strongSelf = weakSelf;  
171 - if(strongSelf){  
172 - [QMUITips hideAllToastInView:strongSelf.view animated:YES];  
173 -  
174 - }  
175 - responseCallback(data);  
176 - }];  
177 -  
178 - // 帮助与反馈 提交反馈后点击完成  
179 - [self.bridge registerHandler:@"wjjFeedbackSuccess" handler:^(id data, WVJBResponseCallback responseCallback) {  
180 - if(TestEnvironment){  
181 - NSLog(@"ObjC Echo called with: %@", data);  
182 - }  
183 - __strong typeof(weakSelf) strongSelf = weakSelf;  
184 - if(strongSelf){  
185 -  
186 - }  
187 - responseCallback(data);  
188 - }];  
189 -  
190 - // h5主动从客户端获取网络状态  
191 - [self.bridge registerHandler:@"wjjJSGetNetStatusFromClient" handler:^(id data, WVJBResponseCallback responseCallback) {  
192 - if(TestEnvironment){  
193 - NSLog(@"ObjC Echo called with: %@", data);  
194 - }  
195 - __strong typeof(weakSelf) strongSelf = weakSelf;  
196 - if(strongSelf){  
197 -  
198 - }  
199 - responseCallback(data);  
200 - }];  
201 -  
202 - // 原生直播/回放无网络时的提示  
203 - [self.bridge registerHandler:@"wjjClickLiveOnLine" handler:^(id data, WVJBResponseCallback responseCallback) {  
204 - if(TestEnvironment){  
205 - NSLog(@"ObjC Echo called with: %@", data);  
206 - }  
207 - __strong typeof(weakSelf) strongSelf = weakSelf;  
208 - if(strongSelf){  
209 - NSDictionary *info = [NSDictionary dictionaryWithDictionary:data];  
210 - if ([[info objectForKey:@"onLine"] isEqualToString:@"NONE"]) {  
211 - dispatch_async(dispatch_get_main_queue(), ^{  
212 - [QMUITips showError:@"网络连接失败" inView:strongSelf.view hideAfterDelay:1.5];  
213 - });  
214 - }  
215 - }  
216 - responseCallback(data);  
217 - }];  
218 -  
219 -}  
220 -  
221 -#pragma mark - 创建导航条  
222 -- (void)setupNavigationBar {  
223 - UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, [UIApplication sharedApplication].statusBarFrame.size.height, [UIScreen mainScreen].bounds.size.width, 44)];  
224 - navView.backgroundColor = [UIColor clearColor];  
225 - [self.view bringSubviewToFront:navView];  
226 - [self.view addSubview:navView];  
227 -  
228 - UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeSystem];  
229 - leftBtn.frame = CGRectMake(0, 0, 44, 44);  
230 - UIImage *leftImage = [self xw_getImageName:@"web_black_back" bundle:@"CNLiveAgreementManager.bundle/CNLiveAgreementManager" targetClass:[CNLiveAgreementWebController class]];  
231 - [leftBtn setImage:[leftImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];  
232 - [leftBtn addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];  
233 - [navView addSubview:leftBtn];  
234 -  
235 - UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeSystem];  
236 - closeBtn.frame = CGRectMake(44, 0, 44, 44);  
237 - UIImage *closeImage = [self xw_getImageName:@"web_black_close" bundle:@"CNLiveAgreementManager.bundle/CNLiveAgreementManager" targetClass:[CNLiveAgreementWebController class]];  
238 - [closeBtn setImage:[closeImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];  
239 - [closeBtn addTarget:self action:@selector(closeClick) forControlEvents:UIControlEventTouchUpInside];  
240 - closeBtn.hidden = !self.isShow;  
241 - [navView addSubview:closeBtn];  
242 -  
243 - UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(([[UIScreen mainScreen] bounds].size.width - 200)/2.0, 0, 200, 44)];  
244 - titleLabel.font = [UIFont boldSystemFontOfSize:17];  
245 - titleLabel.textColor = [UIColor blackColor];  
246 - titleLabel.text = self.name;  
247 - titleLabel.textAlignment = NSTextAlignmentCenter;  
248 - [navView addSubview:titleLabel];  
249 - _titleLabel = titleLabel;  
250 -  
251 -}  
252 -  
253 -- (void)setupUI {  
254 - WKWebViewConfiguration * configuration = [[WKWebViewConfiguration alloc] init];  
255 - configuration.allowsInlineMediaPlayback = YES;  
256 - WKPreferences *preferences = [WKPreferences new];  
257 - preferences.javaScriptCanOpenWindowsAutomatically = YES;  
258 - configuration.preferences = preferences;  
259 - self.webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, [UIApplication sharedApplication].statusBarFrame.size.height+44, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height-([UIApplication sharedApplication].statusBarFrame.size.height+44)) configuration:configuration];  
260 - _webView.UIDelegate = self;  
261 - _webView.navigationDelegate = self;  
262 - _webView.contentMode = UIViewContentModeScaleAspectFit;  
263 - _webView.scrollView.showsHorizontalScrollIndicator = NO;  
264 - _webView.scrollView.showsVerticalScrollIndicator = NO;  
265 - _webView.allowsBackForwardNavigationGestures = YES;  
266 - _webView.allowsLinkPreview = NO;  
267 - [self.view addSubview:self.webView];  
268 -  
269 - self.processView = [[UIProgressView alloc] initWithFrame:CGRectMake(0, ([UIApplication sharedApplication].statusBarFrame.size.height+44)+0.5, [[UIScreen mainScreen] bounds].size.width, 1)];  
270 - _processView.progressTintColor = [UIColor colorWithRed:19/255.0 green:204/255.0 blue:12/255.0 alpha:1.0];  
271 - _processView.trackTintColor = [UIColor whiteColor];  
272 - [self.view addSubview:self.processView];  
273 -  
274 -}  
275 -  
276 -- (void)setupUserAgent {  
277 - NSString *customUserAgent = @";app/plat_a";  
278 -  
279 - if (@available(iOS 12.0, *)) {  
280 - UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero];  
281 - NSString *userAgent = [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];  
282 - NSString *newUserAgent = [userAgent stringByAppendingString:customUserAgent];//自定义需要拼接的字符串  
283 - NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:newUserAgent, @"UserAgent", nil];  
284 -  
285 - [self.webView setCustomUserAgent:newUserAgent];  
286 - [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];  
287 - }  
288 -  
289 - __weak typeof(self) weakSelf = self;  
290 - [self.webView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id result, NSError *error) {  
291 - __strong typeof(weakSelf) strongSelf = weakSelf;  
292 - NSString *userAgent = result;  
293 - NSString *newUserAgent = [userAgent stringByAppendingString:customUserAgent];  
294 - NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:newUserAgent, @"UserAgent", nil];  
295 - [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];  
296 - if (@available(iOS 9.0, *)) {  
297 - [strongSelf.webView setCustomUserAgent:newUserAgent];  
298 - }  
299 - }];  
300 -  
301 - [self.webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];  
302 - if (!self.name) {  
303 - [self.webView addObserver:self forKeyPath:@"title" options:NSKeyValueObservingOptionNew context:NULL];  
304 - }  
305 -}  
306 -  
307 -#pragma mark - WKNavigationDelegate  
308 -// 在发送请求之前,决定是否跳转  
309 -- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler{  
310 - //允许跳转  
311 - decisionHandler(WKNavigationActionPolicyAllow);  
312 -  
313 -}  
314 -  
315 -// 页面开始加载时调用  
316 -- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{  
317 -  
318 -}  
319 -  
320 -// 在收到响应后,决定是否跳转  
321 -- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler{  
322 - //允许跳转  
323 - decisionHandler(WKNavigationResponsePolicyAllow);  
324 - //不允许跳转  
325 - //decisionHandler(WKNavigationResponsePolicyCancel);  
326 -}  
327 -  
328 -// 当内容开始返回时调用  
329 -- (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation{  
330 -  
331 -}  
332 -  
333 -// 页面加载完成之后调用  
334 -- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{  
335 -  
336 -}  
337 -  
338 -// 页面加载失败时调用  
339 -- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(nonnull NSError *)error{  
340 - NSLog(@"打印这个error%@",error);  
341 -  
342 -}  
343 -  
344 -// 接收到服务器跳转请求之后调用(重定向)  
345 -- (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation{  
346 -  
347 -}  
348 -  
349 -#pragma mark - 响应方法  
350 -//回退goBack  
351 -- (void)goBack {  
352 - if ([self.webView canGoBack]) {  
353 - [self.webView goBack];  
354 - }  
355 - else {  
356 - [self closeClick];  
357 - }  
358 -}  
359 -  
360 -//关闭pop  
361 -- (void)closeClick {  
362 - if (self.presentingViewController != nil) {  
363 - [self dismissViewControllerAnimated:YES completion:nil];  
364 -  
365 - }  
366 - else {  
367 - [self.navigationController popViewControllerAnimated:YES];  
368 - }  
369 -}  
370 -  
371 -#pragma mark - KVO  
372 -- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {  
373 - if ([keyPath isEqualToString:@"estimatedProgress"]) {  
374 - if (object == self.webView) {  
375 - [self.processView setAlpha:1.0f];  
376 - [self.processView setProgress:self.webView.estimatedProgress animated:YES];  
377 -  
378 - if(self.webView.estimatedProgress >= 1.0f) {  
379 -  
380 - [UIView animateWithDuration:0.3 delay:0.5 options:UIViewAnimationOptionCurveEaseOut animations:^{  
381 - [self.processView setAlpha:0.0f];  
382 -  
383 - } completion:^(BOOL finished) {  
384 - [self.processView setProgress:0.0f animated:NO];  
385 -  
386 - }];  
387 -  
388 - }  
389 -  
390 - }  
391 - else {  
392 - [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];  
393 - }  
394 -  
395 - }  
396 - else if ([keyPath isEqualToString:@"title"]){  
397 - if (object == self.webView) {  
398 - if (self.webView.title.length != 0) {  
399 - self.name = self.webView.title;  
400 -  
401 - }  
402 - }  
403 - else {  
404 - [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];  
405 - }  
406 - }  
407 - else {  
408 - [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];  
409 -  
410 - }  
411 -}  
412 -#pragma mark - 懒加载  
413 -- (NSMutableArray *)photos{  
414 - if(!_photos){  
415 - _photos = [[NSMutableArray alloc]init];  
416 - }  
417 - return _photos;  
418 -}  
419 -  
420 -#pragma mark - 私有方法  
421 -// 清除缓存  
422 -- (void)clearWKCache {  
423 - NSArray *types = @[WKWebsiteDataTypeDiskCache,WKWebsiteDataTypeOfflineWebApplicationCache,WKWebsiteDataTypeMemoryCache,WKWebsiteDataTypeIndexedDBDatabases,WKWebsiteDataTypeWebSQLDatabases];  
424 - NSSet *websiteDataTypes = [NSSet setWithArray:types];  
425 - NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0];  
426 - [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{  
427 - if(TestEnvironment){  
428 - NSLog(@"CNUserAgreementWebController 缓存清理完毕");  
429 - }  
430 - }];  
431 -  
432 -}  
433 -  
434 -/**  
435 - * 创建图片  
436 - *  
437 - * @param imageName 图片名字  
438 - * @param bundlePath 图片所在的bundle名字  
439 - * @param targetClass 类和bundle的同级目录  
440 - * @return 返回UIImage  
441 - */  
442 -- (UIImage *)xw_getImageName:(NSString *)imageName bundle:(NSString *)bundlePath targetClass:(Class)targetClass{  
443 - NSBundle *bundle = [NSBundle bundleForClass:targetClass];  
444 - NSURL *url = [bundle URLForResource:bundlePath withExtension:@"bundle"];  
445 - NSBundle *targetBundle = [NSBundle bundleWithURL:url];  
446 - UIImage *image = [UIImage imageNamed:imageName inBundle:targetBundle compatibleWithTraitCollection:nil];  
447 - return image?image:[UIImage imageNamed:imageName inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil];  
448 -  
449 -}  
450 -  
451 -#pragma mark - 上传图片到七牛  
452 -// 获取图片的token  
453 -- (void)getImageToken {  
454 - NSDictionary *param = @{@"appId":AppId,  
455 - @"verb":@"POST",  
456 - @"storageType":@"2",  
457 - @"bucket":API_BucketName,  
458 - @"timestamp":[self currentTimestamp]  
459 - };  
460 - [QMUITips showLoading:@"正在提交" inView:self.view];  
461 - __weak typeof(self) weakSelf = self;  
462 - [CNLiveNetworking setAllowRequestDefaultArgument:NO];  
463 - [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:CNUploadAuthForApp Param:param CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {  
464 - __strong typeof(weakSelf) strongSelf = weakSelf;  
465 - if(!strongSelf) return ;  
466 - if ([responseObject isKindOfClass:[NSDictionary class]]) {  
467 - NSDictionary *dic = (NSDictionary *)responseObject;  
468 - if (!error && dic[@"token"] && ![dic[@"token"] isEqualToString:@""]) {  
469 - [self cn_QNStartUploadImageWithToken:dic[@"token"]];  
470 - return;  
471 - }  
472 -  
473 - }  
474 - [QMUITips hideAllToastInView:strongSelf.view animated:YES];  
475 - [QMUITips showError:@"提交失败" inView:strongSelf.view hideAfterDelay:1.5];  
476 -  
477 - }];  
478 -  
479 -}  
480 -  
481 -// 图片开始上传  
482 -- (void)cn_QNStartUploadImageWithToken:(NSString *)token {  
483 - __weak typeof(self) weakSelf = self;  
484 - // 图片视频压缩(LXG)  
485 - [_photos enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {  
486 - if (!weakSelf.photos[idx]) {  
487 - [QMUITips hideAllToastInView:weakSelf.view animated:YES];  
488 - [QMUITips showError:@"提交失败" inView:weakSelf.view hideAfterDelay:1.5];  
489 - return;  
490 - }  
491 -// NSData *zipData = [UIImage zipNSDataWithImage:weakSelf.photos[idx]];//非原图压缩  
492 -// if (zipData.length > kFriendsCircle_limit_photo) {//压缩后大于20M  
493 -// [QMUITips hideAllToastInView:weakSelf.view animated:YES];  
494 -// [QMUITips showError:@"图片过大" inView:weakSelf.view hideAfterDelay:1.5];  
495 -// return;  
496 -// }  
497 -// else{  
498 -// weakSelf.photos[idx] = [UIImage imageWithData:zipData];  
499 -// }  
500 -  
501 - }];  
502 -  
503 - __block  
504 - __block NSMutableArray *keyArr = [NSMutableArray array];  
505 - __block NSMutableArray *picArr = [NSMutableArray array];  
506 -  
507 - for (int i = 0; i < _photos.count; i++) {  
508 - @autoreleasepool {  
509 - UIImage *image = _photos[i];  
510 - __block NSData *imageData = UIImageJPEGRepresentation(image, 1);  
511 - NSString *timeTampStr = [self get13tsRandTimeStr];  
512 - NSString *qiniuFileName = [NSString stringWithFormat:@"%@/%@.jpg",[self getImageBuketkeyFromServerWithExt], timeTampStr];  
513 - QNUploadManager *uploadManager = [QNUploadManager sharedInstanceWithConfiguration:nil];  
514 - [uploadManager putData:imageData key:qiniuFileName token:token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {  
515 - __strong typeof(weakSelf) strongSelf = weakSelf;  
516 - if(!strongSelf) return ;  
517 - if (info.ok) {  
518 - [keyArr addObject:key];  
519 -  
520 - NSString *imageUrl = [NSString stringWithFormat:@"%@%@",API_PhotoUrl,key];  
521 - NSMutableDictionary *picDic = [NSMutableDictionary dictionary];  
522 - [picDic setObject:imageUrl ? imageUrl : @"" forKey:@"imageUrl"];  
523 - [picDic setObject:[NSString stringWithFormat:@"%.0f",image.size.width] forKey:@"imageWidth"];  
524 - [picDic setObject:[NSString stringWithFormat:@"%.0f",image.size.height] forKey:@"imageHeight"];  
525 - [picArr addObject:picDic];  
526 -  
527 - if (keyArr.count == strongSelf.photos.count) {  
528 - id data = @{ @"images": picArr.copy };  
529 - [strongSelf.photos removeAllObjects];  
530 - // 帮助与反馈->产品建议App->h5图片urls  
531 - [strongSelf.bridge callHandler:@"wjjSubmitSuccess" data:data responseCallback:^(id responseData) {  
532 - if(TestEnvironment){  
533 - NSLog(@"ObjC received response: %@", responseData);  
534 - }  
535 - }];  
536 - }  
537 -  
538 - } else if (info.broken) {  
539 - [QMUITips hideAllToastInView:strongSelf.view animated:YES];  
540 - [QMUITips showError:@"网络连接失败" inView:strongSelf.view hideAfterDelay:1.5];  
541 - return ;  
542 - } else {  
543 - [QMUITips hideAllToastInView:strongSelf.view animated:YES];  
544 - [QMUITips showError:info.error.localizedDescription inView:strongSelf.view hideAfterDelay:1.5];  
545 - return ;  
546 - }  
547 -  
548 - } option:nil];  
549 - }  
550 - }  
551 -}  
552 -  
553 -//获取当前时间戳  
554 -- (NSString *)currentTimestamp{  
555 - NSDate *datenow = [NSDate date];  
556 - NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[datenow timeIntervalSince1970]];  
557 - return timeSp;  
558 -  
559 -}  
560 -  
561 -- (NSString *)get13tsRandTimeStr {  
562 - NSString *str1 = [NSString stringWithFormat:@"%d",arc4random() % 10];  
563 - NSString *str2 = [NSString stringWithFormat:@"%d",arc4random() % 10];  
564 - NSString *str3 = [NSString stringWithFormat:@"%d",arc4random() % 10];  
565 - NSString *str4 = [NSString stringWithFormat:@"%d",arc4random() % 10];  
566 - NSString *str5 = [NSString stringWithFormat:@"%d",arc4random() % 10];  
567 - NSString *str6 = [NSString stringWithFormat:@"%d",arc4random() % 10];  
568 - NSString *str7 = [NSString stringWithFormat:@"%d",arc4random() % 10];  
569 - NSString *str8 = [NSString stringWithFormat:@"%d",arc4random() % 10];  
570 -  
571 - NSString *randTimeStr = [NSString stringWithFormat:@"%@%@%@%@%@%@%@%@%@",[self currentTimestamp],str1,str2,str3,str4,str5,str6,str7,str8];  
572 - return randTimeStr;  
573 -  
574 -}  
575 -  
576 -- (NSString *)getImageBuketkeyFromServerWithExt{  
577 -// NSString *spid = [CNLiveBusinessTools getSpid];  
578 -// NSString *imgBucketKey = [NSString stringWithFormat:@"%@/img", spid];  
579 -// NSString *yearTime = [CNLiveTimeTools getyyMMdd];  
580 -// NSString *bucketKey = [NSString stringWithFormat:@"%@/%@",imgBucketKey,yearTime];  
581 -// return bucketKey;  
582 - return @"";  
583 -  
584 -}  
585 -  
586 -@end  
CNLiveUserAgreementManager/Classes/CNLiveAgreementManager.h renamed to CNLiveUserAgreementManager/Classes/CNLiveUserAgreementManager.h
1 // 1 //
2 -// CNLiveAgreementManager.h  
3 -// Test 2 +// CNLiveUserAgreementManager.h
  3 +// CNLiveUserAgreementManager
4 // 4 //
5 -// Created by CNLive-zxw on 2019/4/13.  
6 -// Copyright © 2019 CNLive. All rights reserved. 5 +// Created by 153993236@qq.com on 04/13/2019.
  6 +// Copyright (c) 2019 153993236@qq.com. All rights reserved.
7 // 7 //
8 8
9 #import <Foundation/Foundation.h> 9 #import <Foundation/Foundation.h>
10 10
11 NS_ASSUME_NONNULL_BEGIN 11 NS_ASSUME_NONNULL_BEGIN
12 12
13 -typedef NS_ENUM(NSUInteger, CNGetAgreementH5Type) {  
14 - CNAgreementUser = 1001,//用户协议  
15 - CNAgreementPrivacy = 1002,//隐私政策  
16 - CNAgreementHelp = 1003,//帮助与反馈  
17 - CNAgreementUnderstand = 1004,//使用手册  
18 - CNAgreementIntroduction = 1005,//应用简介  
19 - CNAgreementCopyright = 1006,//版权信息  
20 - CNAgreementPermission = 1007,//软件许可及服务协议  
21 - CNAgreementIntegralRules = 1008,//积分规则  
22 - CNAgreementSigninRules = 1009,//签到奖励规则  
23 - CNAgreementReviewApply = 1010,//复核申请  
24 - CNAgreementCancellation = 1011,//注销协议  
25 - CNAgreementEmojiService = 1012,//表情包服务说明  
26 - CNAgreementEmojiComplaints = 1013,//表情包投诉说明  
27 - CNAgreementEnterpriseQualification = 1014,//企业资质  
28 - CNAgreementBuyAudio = 1015 //购买音频协议 13 +typedef NS_ENUM(NSUInteger, CNLiveGetAgreementH5Type) {
  14 + CNLiveUserAgreementUser = 1001,//用户协议
  15 + CNLiveUserAgreementPrivacy = 1002,//隐私政策
  16 + CNLiveUserAgreementHelp = 1003,//帮助与反馈
  17 + CNLiveUserAgreementUnderstand = 1004,//使用手册
  18 + CNLiveUserAgreementIntroduction = 1005,//应用简介
  19 + CNLiveUserAgreementCopyright = 1006,//版权信息
  20 + CNLiveUserAgreementPermission = 1007,//软件许可及服务协议
  21 + CNLiveUserAgreementIntegralRules = 1008,//积分规则
  22 + CNLiveUserAgreementSigninRules = 1009,//签到奖励规则
  23 + CNLiveUserAgreementReviewApply = 1010,//复核申请
  24 + CNLiveUserAgreementCancellation = 1011,//注销协议
  25 + CNLiveUserAgreementEmojiService = 1012,//表情包服务说明
  26 + CNLiveUserAgreementEmojiComplaints = 1013,//表情包投诉说明
  27 + CNLiveUserAgreementEnterpriseQualification = 1014,//企业资质
  28 + CNLiveUserAgreementBuyAudio = 1015 //购买音频协议
29 29
30 }; 30 };
31 31
32 typedef void(^SuccessBlock)(NSString *h5, NSString *title, BOOL isShow); 32 typedef void(^SuccessBlock)(NSString *h5, NSString *title, BOOL isShow);
33 typedef void(^FailureBlock)(NSError *error); 33 typedef void(^FailureBlock)(NSError *error);
34 34
35 -@interface CNLiveAgreementManager : NSObject 35 +@interface CNLiveUserAgreementManager : NSObject
36 36
37 + (instancetype)manager; 37 + (instancetype)manager;
38 38
@@ -62,7 +62,7 @@ typedef void(^FailureBlock)(NSError *error); @@ -62,7 +62,7 @@ typedef void(^FailureBlock)(NSError *error);
62 * 请求协议并跳转 62 * 请求协议并跳转
63 * @param type 类型 63 * @param type 类型
64 */ 64 */
65 -+ (void)jumpToAgreementH5WithType:(CNGetAgreementH5Type)type; 65 ++ (void)jumpToAgreementH5WithType:(CNLiveGetAgreementH5Type)type;
66 66
67 /** 67 /**
68 * 类方法 请求协议 68 * 类方法 请求协议
@@ -70,7 +70,7 @@ typedef void(^FailureBlock)(NSError *error); @@ -70,7 +70,7 @@ typedef void(^FailureBlock)(NSError *error);
70 * @param success 请求成功回调 70 * @param success 请求成功回调
71 * @param failure 请求失败回调 71 * @param failure 请求失败回调
72 */ 72 */
73 -+ (void)getAgreementH5WithType:(CNGetAgreementH5Type)type success:(SuccessBlock)success failure:(FailureBlock)failure; 73 ++ (void)getAgreementH5WithType:(CNLiveGetAgreementH5Type)type success:(SuccessBlock)success failure:(FailureBlock)failure;
74 74
75 /** 75 /**
76 * 对象方法 请求协议 76 * 对象方法 请求协议
@@ -78,7 +78,7 @@ typedef void(^FailureBlock)(NSError *error); @@ -78,7 +78,7 @@ typedef void(^FailureBlock)(NSError *error);
78 * @param success 请求成功回调 78 * @param success 请求成功回调
79 * @param failure 请求失败回调 79 * @param failure 请求失败回调
80 */ 80 */
81 -- (void)getAgreementH5WithType:(CNGetAgreementH5Type)type success:(SuccessBlock)success failure:(FailureBlock)failure; 81 +- (void)getAgreementH5WithType:(CNLiveGetAgreementH5Type)type success:(SuccessBlock)success failure:(FailureBlock)failure;
82 82
83 @end 83 @end
84 84
CNLiveUserAgreementManager/Classes/CNLiveAgreementManager.m renamed to CNLiveUserAgreementManager/Classes/CNLiveUserAgreementManager.m
1 // 1 //
2 -// CNLiveAgreementManager.m  
3 -// Test 2 +// CNLiveUserAgreementManager.h
  3 +// CNLiveUserAgreementManager
4 // 4 //
5 -// Created by CNLive-zxw on 2019/4/13.  
6 -// Copyright © 2019 CNLive. All rights reserved. 5 +// Created by 153993236@qq.com on 04/13/2019.
  6 +// Copyright (c) 2019 153993236@qq.com. All rights reserved.
7 // 7 //
8 -  
9 -#import "CNLiveAgreementManager.h" 8 +#import "CNLiveUserAgreementManager.h"
10 #import <CNLiveRequestBastKit/CNLiveNetworking.h> 9 #import <CNLiveRequestBastKit/CNLiveNetworking.h>
11 #import "CNLiveEnvironment.h" 10 #import "CNLiveEnvironment.h"
12 -#import "CNLiveAgreementWebController.h" 11 +#import "CNLiveUserAgreementWebController.h"
13 12
14 -@interface CNLiveAgreementManager() 13 +@interface CNLiveUserAgreementManager()
15 14
16 15
17 @end 16 @end
18 17
19 -@implementation CNLiveAgreementManager 18 +@implementation CNLiveUserAgreementManager
20 19
21 -static CNLiveAgreementManager *_instance = nil; 20 +static CNLiveUserAgreementManager *_instance = nil;
22 21
23 /** 22 /**
24 * @abstract 单例初始化 23 * @abstract 单例初始化
@@ -26,7 +25,7 @@ static CNLiveAgreementManager *_instance = nil; @@ -26,7 +25,7 @@ static CNLiveAgreementManager *_instance = nil;
26 + (instancetype)manager{ 25 + (instancetype)manager{
27 static dispatch_once_t once; 26 static dispatch_once_t once;
28 dispatch_once(&once, ^{ 27 dispatch_once(&once, ^{
29 - _instance = [[CNLiveAgreementManager alloc]init]; 28 + _instance = [[CNLiveUserAgreementManager alloc]init];
30 }); 29 });
31 return _instance; 30 return _instance;
32 } 31 }
@@ -54,7 +53,7 @@ static CNLiveAgreementManager *_instance = nil; @@ -54,7 +53,7 @@ static CNLiveAgreementManager *_instance = nil;
54 * @param success 请求成功回调 53 * @param success 请求成功回调
55 * @param failure 请求失败回调 54 * @param failure 请求失败回调
56 */ 55 */
57 -- (void)getAgreementH5WithType:(CNGetAgreementH5Type)type success:(SuccessBlock)success failure:(FailureBlock)failure { 56 +- (void)getAgreementH5WithType:(CNLiveGetAgreementH5Type)type success:(SuccessBlock)success failure:(FailureBlock)failure {
58 [CNLiveNetworking setAllowRequestDefaultArgument:NO]; 57 [CNLiveNetworking setAllowRequestDefaultArgument:NO];
59 [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodGET URLString:CNGetAgreementH5Url Param:@{} CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) { 58 [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodGET URLString:CNGetAgreementH5Url Param:@{} CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
60 if (error) { 59 if (error) {
@@ -68,7 +67,7 @@ static CNLiveAgreementManager *_instance = nil; @@ -68,7 +67,7 @@ static CNLiveAgreementManager *_instance = nil;
68 for (NSDictionary *dic in responseObject) { 67 for (NSDictionary *dic in responseObject) {
69 68
70 switch (type) { 69 switch (type) {
71 - case CNAgreementUser: 70 + caseCNLiveUserAgreementUser:
72 { 71 {
73 if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"yhxy"]) { 72 if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"yhxy"]) {
74 if (success) { 73 if (success) {
@@ -78,7 +77,7 @@ static CNLiveAgreementManager *_instance = nil; @@ -78,7 +77,7 @@ static CNLiveAgreementManager *_instance = nil;
78 } 77 }
79 } 78 }
80 break; 79 break;
81 - case CNAgreementPrivacy: 80 + caseCNLiveUserAgreementPrivacy:
82 { 81 {
83 if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"yszc"]) { 82 if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"yszc"]) {
84 if (success) { 83 if (success) {
@@ -88,7 +87,7 @@ static CNLiveAgreementManager *_instance = nil; @@ -88,7 +87,7 @@ static CNLiveAgreementManager *_instance = nil;
88 } 87 }
89 } 88 }
90 break; 89 break;
91 - case CNAgreementHelp: 90 + caseCNLiveUserAgreementHelp:
92 { 91 {
93 if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"bzfk"]) { 92 if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"bzfk"]) {
94 if (success) { 93 if (success) {
@@ -98,7 +97,7 @@ static CNLiveAgreementManager *_instance = nil; @@ -98,7 +97,7 @@ static CNLiveAgreementManager *_instance = nil;
98 } 97 }
99 } 98 }
100 break; 99 break;
101 - case CNAgreementUnderstand: 100 + caseCNLiveUserAgreementUnderstand:
102 { 101 {
103 if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"ljwjj"]) { 102 if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"ljwjj"]) {
104 if (success) { 103 if (success) {
@@ -108,7 +107,7 @@ static CNLiveAgreementManager *_instance = nil; @@ -108,7 +107,7 @@ static CNLiveAgreementManager *_instance = nil;
108 } 107 }
109 } 108 }
110 break; 109 break;
111 - case CNAgreementIntroduction: 110 + caseCNLiveUserAgreementIntroduction:
112 { 111 {
113 if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"yyjj"]) { 112 if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"yyjj"]) {
114 if (success) { 113 if (success) {
@@ -118,7 +117,7 @@ static CNLiveAgreementManager *_instance = nil; @@ -118,7 +117,7 @@ static CNLiveAgreementManager *_instance = nil;
118 } 117 }
119 } 118 }
120 break; 119 break;
121 - case CNAgreementCopyright: 120 + caseCNLiveUserAgreementCopyright:
122 { 121 {
123 if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"bqxx"]) { 122 if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"bqxx"]) {
124 if (success) { 123 if (success) {
@@ -128,7 +127,7 @@ static CNLiveAgreementManager *_instance = nil; @@ -128,7 +127,7 @@ static CNLiveAgreementManager *_instance = nil;
128 } 127 }
129 } 128 }
130 break; 129 break;
131 - case CNAgreementPermission: 130 + caseCNLiveUserAgreementPermission:
132 { 131 {
133 if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"rjxkxy"]) { 132 if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"rjxkxy"]) {
134 if (success) { 133 if (success) {
@@ -138,7 +137,7 @@ static CNLiveAgreementManager *_instance = nil; @@ -138,7 +137,7 @@ static CNLiveAgreementManager *_instance = nil;
138 } 137 }
139 } 138 }
140 break; 139 break;
141 - case CNAgreementIntegralRules: 140 + caseCNLiveUserAgreementIntegralRules:
142 { 141 {
143 if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"jfgz"]) { 142 if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"jfgz"]) {
144 if (success) { 143 if (success) {
@@ -148,7 +147,7 @@ static CNLiveAgreementManager *_instance = nil; @@ -148,7 +147,7 @@ static CNLiveAgreementManager *_instance = nil;
148 } 147 }
149 } 148 }
150 break; 149 break;
151 - case CNAgreementSigninRules: 150 + caseCNLiveUserAgreementSigninRules:
152 { 151 {
153 if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"jfjlgz"]) { 152 if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"jfjlgz"]) {
154 if (success) { 153 if (success) {
@@ -158,7 +157,7 @@ static CNLiveAgreementManager *_instance = nil; @@ -158,7 +157,7 @@ static CNLiveAgreementManager *_instance = nil;
158 } 157 }
159 } 158 }
160 break; 159 break;
161 - case CNAgreementReviewApply: 160 + caseCNLiveUserAgreementReviewApply:
162 { 161 {
163 if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"shsqxy"]) { 162 if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"shsqxy"]) {
164 if (success) { 163 if (success) {
@@ -168,7 +167,7 @@ static CNLiveAgreementManager *_instance = nil; @@ -168,7 +167,7 @@ static CNLiveAgreementManager *_instance = nil;
168 } 167 }
169 } 168 }
170 break; 169 break;
171 - case CNAgreementCancellation: 170 + caseCNLiveUserAgreementCancellation:
172 { 171 {
173 if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"zxxz"]) { 172 if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"zxxz"]) {
174 if (success) { 173 if (success) {
@@ -178,7 +177,7 @@ static CNLiveAgreementManager *_instance = nil; @@ -178,7 +177,7 @@ static CNLiveAgreementManager *_instance = nil;
178 } 177 }
179 } 178 }
180 break; 179 break;
181 - case CNAgreementEmojiService: 180 + caseCNLiveUserAgreementEmojiService:
182 { 181 {
183 if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"fwsm"]) { 182 if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"fwsm"]) {
184 if (success) { 183 if (success) {
@@ -188,7 +187,7 @@ static CNLiveAgreementManager *_instance = nil; @@ -188,7 +187,7 @@ static CNLiveAgreementManager *_instance = nil;
188 } 187 }
189 } 188 }
190 break; 189 break;
191 - case CNAgreementEmojiComplaints: 190 + caseCNLiveUserAgreementEmojiComplaints:
192 { 191 {
193 if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"tssm"]) { 192 if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"tssm"]) {
194 if (success) { 193 if (success) {
@@ -198,7 +197,7 @@ static CNLiveAgreementManager *_instance = nil; @@ -198,7 +197,7 @@ static CNLiveAgreementManager *_instance = nil;
198 } 197 }
199 } 198 }
200 break; 199 break;
201 - case CNAgreementEnterpriseQualification: 200 + caseCNLiveUserAgreementEnterpriseQualification:
202 { 201 {
203 if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"qyzz"]) { 202 if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"qyzz"]) {
204 if (success) { 203 if (success) {
@@ -208,7 +207,7 @@ static CNLiveAgreementManager *_instance = nil; @@ -208,7 +207,7 @@ static CNLiveAgreementManager *_instance = nil;
208 } 207 }
209 } 208 }
210 break; 209 break;
211 - case CNAgreementBuyAudio: 210 + caseCNLiveUserAgreementBuyAudio:
212 { 211 {
213 if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"ypxy"]) { 212 if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"ypxy"]) {
214 if (success) { 213 if (success) {
@@ -239,8 +238,8 @@ static CNLiveAgreementManager *_instance = nil; @@ -239,8 +238,8 @@ static CNLiveAgreementManager *_instance = nil;
239 * @param success 请求成功回调 238 * @param success 请求成功回调
240 * @param failure 请求失败回调 239 * @param failure 请求失败回调
241 */ 240 */
242 -+ (void)getAgreementH5WithType:(CNGetAgreementH5Type)type success:(SuccessBlock)success failure:(FailureBlock)failure {  
243 - [[CNLiveAgreementManager manager] getAgreementH5WithType:type success:^(NSString * _Nonnull h5, NSString * _Nonnull title, BOOL isShow) { 241 ++ (void)getAgreementH5WithType:(CNLiveGetAgreementH5Type)type success:(SuccessBlock)success failure:(FailureBlock)failure {
  242 + [[CNLiveUserAgreementManager manager] getAgreementH5WithType:type success:^(NSString * _Nonnull h5, NSString * _Nonnull title, BOOL isShow) {
244 success?success(h5, title, isShow):@""; 243 success?success(h5, title, isShow):@"";
245 244
246 } failure:^(NSError * _Nonnull error) { 245 } failure:^(NSError * _Nonnull error) {
@@ -254,9 +253,9 @@ static CNLiveAgreementManager *_instance = nil; @@ -254,9 +253,9 @@ static CNLiveAgreementManager *_instance = nil;
254 * 请求协议并跳转 253 * 请求协议并跳转
255 * @param type 类型 254 * @param type 类型
256 */ 255 */
257 -+ (void)jumpToAgreementH5WithType:(CNGetAgreementH5Type)type{ 256 ++ (void)jumpToAgreementH5WithType:(CNLiveGetAgreementH5Type)type{
258 __weak typeof(self) weakSelf = self; 257 __weak typeof(self) weakSelf = self;
259 - [CNLiveAgreementManager getAgreementH5WithType:type success:^(NSString *h5, NSString *title, BOOL isShow) { 258 + [CNLiveUserAgreementManager getAgreementH5WithType:type success:^(NSString *h5, NSString *title, BOOL isShow) {
260 __strong typeof(weakSelf) strongSelf = weakSelf; 259 __strong typeof(weakSelf) strongSelf = weakSelf;
261 if(!strongSelf) return; 260 if(!strongSelf) return;
262 [strongSelf pushToWebControllerUrl:h5 name:title showCloseBtn:isShow]; 261 [strongSelf pushToWebControllerUrl:h5 name:title showCloseBtn:isShow];
@@ -277,7 +276,7 @@ static CNLiveAgreementManager *_instance = nil; @@ -277,7 +276,7 @@ static CNLiveAgreementManager *_instance = nil;
277 */ 276 */
278 + (void)jumpToAgreementH5WithString:(NSString *)string { 277 + (void)jumpToAgreementH5WithString:(NSString *)string {
279 __weak typeof(self) weakSelf = self; 278 __weak typeof(self) weakSelf = self;
280 - [CNLiveAgreementManager getAgreementH5WithString:string success:^(NSString *h5, NSString *title, BOOL isShow) { 279 + [CNLiveUserAgreementManager getAgreementH5WithString:string success:^(NSString *h5, NSString *title, BOOL isShow) {
281 __strong typeof(weakSelf) strongSelf = weakSelf; 280 __strong typeof(weakSelf) strongSelf = weakSelf;
282 if(!strongSelf) return; 281 if(!strongSelf) return;
283 [strongSelf pushToWebControllerUrl:h5 name:title showCloseBtn:isShow]; 282 [strongSelf pushToWebControllerUrl:h5 name:title showCloseBtn:isShow];
@@ -298,7 +297,7 @@ static CNLiveAgreementManager *_instance = nil; @@ -298,7 +297,7 @@ static CNLiveAgreementManager *_instance = nil;
298 * @param failure 请求失败回调 297 * @param failure 请求失败回调
299 */ 298 */
300 + (void)getAgreementH5WithString:(NSString *)string success:(SuccessBlock)success failure:(FailureBlock)failure{ 299 + (void)getAgreementH5WithString:(NSString *)string success:(SuccessBlock)success failure:(FailureBlock)failure{
301 - [[CNLiveAgreementManager manager] getAgreementH5WithString:string success:^(NSString *h5, NSString *title, BOOL isShow) { 300 + [[CNLiveUserAgreementManager manager] getAgreementH5WithString:string success:^(NSString *h5, NSString *title, BOOL isShow) {
302 success?success(h5, title, isShow):@""; 301 success?success(h5, title, isShow):@"";
303 302
304 } failure:^(NSError *error) { 303 } failure:^(NSError *error) {
@@ -344,7 +343,7 @@ static CNLiveAgreementManager *_instance = nil; @@ -344,7 +343,7 @@ static CNLiveAgreementManager *_instance = nil;
344 //跟控制器是Navigation 343 //跟控制器是Navigation
345 if ([root isKindOfClass:[UINavigationController class]]){ 344 if ([root isKindOfClass:[UINavigationController class]]){
346 UINavigationController *nav = (UINavigationController *)root; 345 UINavigationController *nav = (UINavigationController *)root;
347 - CNLiveAgreementWebController *vc = [[CNLiveAgreementWebController alloc] initWithUrl:url name:name showCloseBtn:isShow]; 346 + CNLiveUserAgreementWebController *vc = [[CNLiveUserAgreementWebController alloc] initWithUrl:url name:name showCloseBtn:isShow];
348 [nav pushViewController:vc animated:YES]; 347 [nav pushViewController:vc animated:YES];
349 348
350 } 349 }
@@ -352,11 +351,11 @@ static CNLiveAgreementManager *_instance = nil; @@ -352,11 +351,11 @@ static CNLiveAgreementManager *_instance = nil;
352 else if ([root isKindOfClass:[UITabBarController class]]){ 351 else if ([root isKindOfClass:[UITabBarController class]]){
353 UITabBarController *tab = (UITabBarController *)root; 352 UITabBarController *tab = (UITabBarController *)root;
354 UINavigationController *nav = tab.selectedViewController; 353 UINavigationController *nav = tab.selectedViewController;
355 - CNLiveAgreementWebController *vc = [[CNLiveAgreementWebController alloc] initWithUrl:url name:name showCloseBtn:isShow]; 354 + CNLiveUserAgreementWebController *vc = [[CNLiveUserAgreementWebController alloc] initWithUrl:url name:name showCloseBtn:isShow];
356 [nav pushViewController:vc animated:YES]; 355 [nav pushViewController:vc animated:YES];
357 356
358 }else{ 357 }else{
359 - CNLiveAgreementWebController *vc = [[CNLiveAgreementWebController alloc] initWithUrl:url name:name showCloseBtn:isShow]; 358 + CNLiveUserAgreementWebController *vc = [[CNLiveUserAgreementWebController alloc] initWithUrl:url name:name showCloseBtn:isShow];
360 [root presentViewController:vc animated:YES completion:nil]; 359 [root presentViewController:vc animated:YES completion:nil];
361 360
362 } 361 }
CNLiveUserAgreementManager/Classes/CNLiveAgreementWebController.h renamed to CNLiveUserAgreementManager/Classes/CNLiveUserAgreementWebController.h
1 // 1 //
2 -// CNLiveAgreementWebController.h  
3 -// CNLiveServices_Example 2 +// CNLiveUserAgreementWebController.h
  3 +// CNLiveUserAgreementManager
4 // 4 //
5 -// Created by CNLive-zxw on 2019/7/30.  
6 -// Copyright © 2019 153993236@qq.com. All rights reserved. 5 +// Created by 153993236@qq.com on 04/13/2019.
  6 +// Copyright (c) 2019 153993236@qq.com. All rights reserved.
7 // 7 //
8 8
9 #import <UIKit/UIKit.h> 9 #import <UIKit/UIKit.h>
10 10
11 NS_ASSUME_NONNULL_BEGIN 11 NS_ASSUME_NONNULL_BEGIN
12 12
13 -@interface CNLiveAgreementWebController : UIViewController 13 +@interface CNLiveUserAgreementWebController : UIViewController
14 /** 14 /**
15 * 对象方法 初始化方法 15 * 对象方法 初始化方法
16 * @param url url 16 * @param url url
CNLiveUserAgreementManager/Classes/CNLiveUserAgreementWebController.m 0 → 100644
  1 +//
  2 +// CNLiveUserAgreementWebController.h
  3 +// CNLiveUserAgreementManager
  4 +//
  5 +// Created by 153993236@qq.com on 04/13/2019.
  6 +// Copyright (c) 2019 153993236@qq.com. All rights reserved.
  7 +//
  8 +
  9 +#import "CNLiveUserAgreementWebController.h"
  10 +// 七牛
  11 +#import <WebKit/WebKit.h>
  12 +// 环境库
  13 +#import "CNLiveEnvironment.h"
  14 +
  15 +#import <CNLiveRequestBastKit/CNLiveNetworking.h>
  16 +
  17 +@interface CNLiveUserAgreementWebController ()<WKUIDelegate, WKNavigationDelegate>
  18 +@property (nonatomic, copy) NSString *url;
  19 +@property (nonatomic, copy) NSString *name;
  20 +@property (nonatomic, assign) BOOL isShow;
  21 +
  22 +@property (nonatomic, strong) WKWebView *webView;
  23 +@property (nonatomic, strong) UIProgressView *processView;
  24 +@property (nonatomic, weak) UILabel *titleLabel;
  25 +
  26 +@property (nonatomic, strong) NSMutableArray *photos;// 上传图片
  27 +
  28 +@end
  29 +
  30 +@implementation CNLiveUserAgreementWebController
  31 +#pragma mark - 初始化方法
  32 +- (instancetype)initWithUrl:(NSString *)url name:(nullable NSString *)name showCloseBtn:(BOOL)isShow {
  33 + self = [super init];
  34 + if (self) {
  35 + self.url = url;
  36 + self.name = name;
  37 + self.isShow = isShow;
  38 + }
  39 + return self;
  40 +}
  41 +
  42 +- (void)setName:(NSString *)name{
  43 + _name = name;
  44 + _titleLabel.text = name;
  45 +
  46 +}
  47 +
  48 +#pragma mark - 加载数据
  49 +- (void)loadUrl {
  50 + NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:self.url] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:15.0];
  51 + [self.webView loadRequest:theRequest];
  52 +
  53 +}
  54 +
  55 +#pragma mark - 生命周期
  56 +- (void)viewWillAppear:(BOOL)animated {
  57 + [super viewWillAppear:animated];
  58 + self.navigationController.navigationBarHidden = YES;
  59 +
  60 +}
  61 +
  62 +- (void)viewWillDisappear:(BOOL)animated {
  63 + [super viewWillDisappear:animated];
  64 + self.navigationController.navigationBarHidden = NO;
  65 +
  66 +}
  67 +
  68 +- (void)viewDidLoad {
  69 + [super viewDidLoad];
  70 + self.view.backgroundColor = [UIColor whiteColor];
  71 + if (@available(iOS 11, *)) {
  72 + self.webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
  73 + }
  74 + else {
  75 + self.automaticallyAdjustsScrollViewInsets = NO;
  76 + }
  77 + [self setupNavigationBar];
  78 + [self setupUI];
  79 + [self loadUrl];
  80 +
  81 +}
  82 +
  83 +- (void)dealloc {
  84 + if(TestEnvironment){
  85 + NSLog(@"CNUserLiveAgreementWebController dealloc");
  86 + }
  87 + [self.webView stopLoading];
  88 + [self.webView removeObserver:self forKeyPath:@"estimatedProgress"];
  89 + if (!self.name) {
  90 + [self.webView removeObserver:self forKeyPath:@"title"];
  91 + }
  92 + self.webView.UIDelegate = nil;
  93 + self.webView.navigationDelegate = nil;
  94 + self.webView = nil;
  95 + [self clearWKCache];
  96 +
  97 +}
  98 +
  99 +#pragma mark - 创建导航条
  100 +- (void)setupNavigationBar {
  101 + UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, [UIApplication sharedApplication].statusBarFrame.size.height, [UIScreen mainScreen].bounds.size.width, 44)];
  102 + navView.backgroundColor = [UIColor clearColor];
  103 + [self.view bringSubviewToFront:navView];
  104 + [self.view addSubview:navView];
  105 +
  106 + UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeSystem];
  107 + leftBtn.frame = CGRectMake(15, 0, 44, 44);
  108 + UIImage *leftImage = [self xw_getImageName:@"web_black_back" bundleName:@"CNLiveUserAgreementManager" targetClass:[CNLiveUserAgreementWebController class]];
  109 + [leftBtn setImage:[leftImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
  110 + [leftBtn addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
  111 + [leftBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  112 + [navView addSubview:leftBtn];
  113 +
  114 + UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeSystem];
  115 + closeBtn.frame = CGRectMake(44+15, 0, 44, 44);
  116 + UIImage *closeImage = [self xw_getImageName:@"web_black_close" bundleName:@"CNLiveUserAgreementManager" targetClass:[CNLiveUserAgreementWebController class]];
  117 + [closeBtn setImage:[closeImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
  118 + [closeBtn addTarget:self action:@selector(closeClick) forControlEvents:UIControlEventTouchUpInside];
  119 + [closeBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  120 + closeBtn.hidden = !self.isShow;
  121 + [navView addSubview:closeBtn];
  122 +
  123 + UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(([[UIScreen mainScreen] bounds].size.width - 200)/2.0, 0, 200, 44)];
  124 + titleLabel.font = [UIFont boldSystemFontOfSize:17];
  125 + titleLabel.textColor = [UIColor blackColor];
  126 + titleLabel.text = self.name;
  127 + titleLabel.textAlignment = NSTextAlignmentCenter;
  128 + [navView addSubview:titleLabel];
  129 + _titleLabel = titleLabel;
  130 +
  131 +}
  132 +
  133 +- (void)setupUI {
  134 + WKWebViewConfiguration * configuration = [[WKWebViewConfiguration alloc] init];
  135 + configuration.allowsInlineMediaPlayback = YES;
  136 + WKPreferences *preferences = [WKPreferences new];
  137 + preferences.javaScriptCanOpenWindowsAutomatically = YES;
  138 + configuration.preferences = preferences;
  139 + self.webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, [UIApplication sharedApplication].statusBarFrame.size.height+44, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height-([UIApplication sharedApplication].statusBarFrame.size.height+44)) configuration:configuration];
  140 + _webView.UIDelegate = self;
  141 + _webView.navigationDelegate = self;
  142 + _webView.contentMode = UIViewContentModeScaleAspectFit;
  143 + _webView.scrollView.showsHorizontalScrollIndicator = NO;
  144 + _webView.scrollView.showsVerticalScrollIndicator = NO;
  145 + _webView.allowsBackForwardNavigationGestures = YES;
  146 + _webView.allowsLinkPreview = NO;
  147 + [self.view addSubview:self.webView];
  148 +
  149 + self.processView = [[UIProgressView alloc] initWithFrame:CGRectMake(0, ([UIApplication sharedApplication].statusBarFrame.size.height+44)+0.5, [[UIScreen mainScreen] bounds].size.width, 1)];
  150 + _processView.progressTintColor = [UIColor colorWithRed:19/255.0 green:204/255.0 blue:12/255.0 alpha:1.0];
  151 + _processView.trackTintColor = [UIColor whiteColor];
  152 + [self.view addSubview:self.processView];
  153 +
  154 + [self.webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
  155 + if (!self.name) {
  156 + [self.webView addObserver:self forKeyPath:@"title" options:NSKeyValueObservingOptionNew context:NULL];
  157 + }
  158 +
  159 +}
  160 +
  161 +
  162 +#pragma mark - WKNavigationDelegate
  163 +// 在发送请求之前,决定是否跳转
  164 +- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler{
  165 + //允许跳转
  166 + decisionHandler(WKNavigationActionPolicyAllow);
  167 +
  168 +}
  169 +
  170 +// 页面开始加载时调用
  171 +- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{
  172 +
  173 +}
  174 +
  175 +// 在收到响应后,决定是否跳转
  176 +- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler{
  177 + //允许跳转
  178 + decisionHandler(WKNavigationResponsePolicyAllow);
  179 + //不允许跳转
  180 + //decisionHandler(WKNavigationResponsePolicyCancel);
  181 +}
  182 +
  183 +// 当内容开始返回时调用
  184 +- (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation{
  185 +
  186 +}
  187 +
  188 +// 页面加载完成之后调用
  189 +- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
  190 +
  191 +}
  192 +
  193 +// 页面加载失败时调用
  194 +- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(nonnull NSError *)error{
  195 + NSLog(@"打印这个error%@",error);
  196 +
  197 +}
  198 +
  199 +// 接收到服务器跳转请求之后调用(重定向)
  200 +- (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation{
  201 +
  202 +}
  203 +
  204 +#pragma mark - 响应方法
  205 +//回退goBack
  206 +- (void)goBack {
  207 + if ([self.webView canGoBack]) {
  208 + [self.webView goBack];
  209 + }
  210 + else {
  211 + [self closeClick];
  212 + }
  213 +}
  214 +
  215 +//关闭pop
  216 +- (void)closeClick {
  217 + if (self.presentingViewController != nil) {
  218 + [self dismissViewControllerAnimated:YES completion:nil];
  219 +
  220 + }
  221 + else {
  222 + [self.navigationController popViewControllerAnimated:YES];
  223 + }
  224 +}
  225 +
  226 +#pragma mark - KVO
  227 +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
  228 + if ([keyPath isEqualToString:@"estimatedProgress"]) {
  229 + if (object == self.webView) {
  230 + [self.processView setAlpha:1.0f];
  231 + [self.processView setProgress:self.webView.estimatedProgress animated:YES];
  232 +
  233 + if(self.webView.estimatedProgress >= 1.0f) {
  234 +
  235 + [UIView animateWithDuration:0.3 delay:0.5 options:UIViewAnimationOptionCurveEaseOut animations:^{
  236 + [self.processView setAlpha:0.0f];
  237 +
  238 + } completion:^(BOOL finished) {
  239 + [self.processView setProgress:0.0f animated:NO];
  240 +
  241 + }];
  242 +
  243 + }
  244 +
  245 + }
  246 + else {
  247 + [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
  248 + }
  249 +
  250 + }
  251 + else if ([keyPath isEqualToString:@"title"]){
  252 + if (object == self.webView) {
  253 + if (self.webView.title.length != 0) {
  254 + self.name = self.webView.title;
  255 +
  256 + }
  257 + }
  258 + else {
  259 + [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
  260 + }
  261 + }
  262 + else {
  263 + [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
  264 +
  265 + }
  266 +}
  267 +#pragma mark - 懒加载
  268 +#pragma mark - 私有方法
  269 +// 清除缓存
  270 +- (void)clearWKCache {
  271 + NSArray *types = @[WKWebsiteDataTypeDiskCache,WKWebsiteDataTypeOfflineWebApplicationCache,WKWebsiteDataTypeMemoryCache,WKWebsiteDataTypeIndexedDBDatabases,WKWebsiteDataTypeWebSQLDatabases];
  272 + NSSet *websiteDataTypes = [NSSet setWithArray:types];
  273 + NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
  274 + [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{
  275 + if(TestEnvironment){
  276 + NSLog(@"CNLiveUserAgreementWebController 缓存清理完毕");
  277 + }
  278 + }];
  279 +
  280 +}
  281 +
  282 +/**
  283 + * 创建图片
  284 + *
  285 + * @param imageName 图片名字
  286 + * @param bundleName 图片所在的bundle名字
  287 + * @param targetClass 类和bundle的同级目录
  288 + * @return 返回UIImage
  289 + */
  290 +- (UIImage *)xw_getImageName:(NSString *)imageName bundleName:(NSString *)bundleName targetClass:(Class)targetClass{
  291 + NSBundle *bundle = [NSBundle bundleForClass:targetClass];
  292 + NSURL *url = [bundle URLForResource:bundleName withExtension:@"bundle"];
  293 + NSBundle *targetBundle = [NSBundle bundleWithURL:url];
  294 + UIImage *image = [UIImage imageNamed:imageName inBundle:targetBundle compatibleWithTraitCollection:nil];
  295 + return image?image:[UIImage imageNamed:imageName inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil];
  296 +
  297 +}
  298 +
  299 +@end
Example/CNLiveUserAgreementManager.xcodeproj/project.pbxproj
@@ -61,7 +61,7 @@ @@ -61,7 +61,7 @@
61 6003F5BB195388D20070C39A /* Tests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Tests.m; sourceTree = "<group>"; }; 61 6003F5BB195388D20070C39A /* Tests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Tests.m; sourceTree = "<group>"; };
62 606FC2411953D9B200FFA9A0 /* Tests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Tests-Prefix.pch"; sourceTree = "<group>"; }; 62 606FC2411953D9B200FFA9A0 /* Tests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Tests-Prefix.pch"; sourceTree = "<group>"; };
63 71719F9E1E33DC2100824A3D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; }; 63 71719F9E1E33DC2100824A3D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
64 - 7A1C126D9A48DA93CC000266 /* CNLiveUserAgreementManager.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = CNLiveUserAgreementManager.podspec; path = ../CNLiveUserAgreementManager.podspec; sourceTree = "<group>"; }; 64 + 7A1C126D9A48DA93CC000266 /* CNLiveUserAgreementManager.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = CNLiveUserAgreementManager.podspec; path = ../CNLiveUserAgreementManager.podspec; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
65 873B8AEA1B1F5CCA007FD442 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = Main.storyboard; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; }; 65 873B8AEA1B1F5CCA007FD442 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = Main.storyboard; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
66 919A11E2C0D5C88E34C935D4 /* Pods_CNLiveUserAgreementManager_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_CNLiveUserAgreementManager_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 66 919A11E2C0D5C88E34C935D4 /* Pods_CNLiveUserAgreementManager_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_CNLiveUserAgreementManager_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
67 AACA5F9B3491663272E37D89 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; }; 67 AACA5F9B3491663272E37D89 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
@@ -260,6 +260,7 @@ @@ -260,6 +260,7 @@
260 developmentRegion = English; 260 developmentRegion = English;
261 hasScannedForEncodings = 0; 261 hasScannedForEncodings = 0;
262 knownRegions = ( 262 knownRegions = (
  263 + English,
263 en, 264 en,
264 Base, 265 Base,
265 ); 266 );
@@ -302,31 +303,29 @@ @@ -302,31 +303,29 @@
302 buildActionMask = 2147483647; 303 buildActionMask = 2147483647;
303 files = ( 304 files = (
304 ); 305 );
305 - inputFileListPaths = (  
306 - );  
307 inputPaths = ( 306 inputPaths = (
308 "${PODS_ROOT}/Target Support Files/Pods-CNLiveUserAgreementManager_Example/Pods-CNLiveUserAgreementManager_Example-frameworks.sh", 307 "${PODS_ROOT}/Target Support Files/Pods-CNLiveUserAgreementManager_Example/Pods-CNLiveUserAgreementManager_Example-frameworks.sh",
309 "${BUILT_PRODUCTS_DIR}/AFNetworking/AFNetworking.framework", 308 "${BUILT_PRODUCTS_DIR}/AFNetworking/AFNetworking.framework",
  309 + "${BUILT_PRODUCTS_DIR}/CNLiveBeeHive/CNLiveBeeHive.framework",
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}/CNLiveTripartiteManagement/CNLiveTripartiteManagement.framework",
312 "${BUILT_PRODUCTS_DIR}/CNLiveUserAgreementManager/CNLiveUserAgreementManager.framework", 313 "${BUILT_PRODUCTS_DIR}/CNLiveUserAgreementManager/CNLiveUserAgreementManager.framework",
313 - "${BUILT_PRODUCTS_DIR}/HappyDNS/HappyDNS.framework", 314 + "${BUILT_PRODUCTS_DIR}/CNLiveUserManagement/CNLiveUserManagement.framework",
  315 + "${BUILT_PRODUCTS_DIR}/MJExtension/MJExtension.framework",
314 "${BUILT_PRODUCTS_DIR}/QMUIKit/QMUIKit.framework", 316 "${BUILT_PRODUCTS_DIR}/QMUIKit/QMUIKit.framework",
315 - "${BUILT_PRODUCTS_DIR}/Qiniu/Qiniu.framework",  
316 - "${BUILT_PRODUCTS_DIR}/WebViewJavascriptBridge/WebViewJavascriptBridge.framework",  
317 ); 317 );
318 name = "[CP] Embed Pods Frameworks"; 318 name = "[CP] Embed Pods Frameworks";
319 - outputFileListPaths = (  
320 - );  
321 outputPaths = ( 319 outputPaths = (
322 "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/AFNetworking.framework", 320 "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/AFNetworking.framework",
  321 + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveBeeHive.framework",
323 "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveEnvironment.framework", 322 "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveEnvironment.framework",
324 "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveRequestBastKit.framework", 323 "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveRequestBastKit.framework",
  324 + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveTripartiteManagement.framework",
325 "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveUserAgreementManager.framework", 325 "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveUserAgreementManager.framework",
326 - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/HappyDNS.framework", 326 + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveUserManagement.framework",
  327 + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MJExtension.framework",
327 "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/QMUIKit.framework", 328 "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/QMUIKit.framework",
328 - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Qiniu.framework",  
329 - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/WebViewJavascriptBridge.framework",  
330 ); 329 );
331 runOnlyForDeploymentPostprocessing = 0; 330 runOnlyForDeploymentPostprocessing = 0;
332 shellPath = /bin/sh; 331 shellPath = /bin/sh;
Example/CNLiveUserAgreementManager/CNLiveViewController.m
@@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
7 // 7 //
8 8
9 #import "CNLiveViewController.h" 9 #import "CNLiveViewController.h"
10 -#import "CNLiveAgreementManager.h" 10 +#import "CNLiveUserAgreementManager.h"
11 #import "CNLiveEnvironment.h" 11 #import "CNLiveEnvironment.h"
12 12
13 @interface CNLiveViewController () 13 @interface CNLiveViewController ()
@@ -33,8 +33,8 @@ @@ -33,8 +33,8 @@
33 33
34 } 34 }
35 - (void)testButtonClicked { 35 - (void)testButtonClicked {
36 - [CNLiveAgreementManager jumpToAgreementH5WithType:CNAgreementHelp];  
37 -// [CNLiveAgreementManager jumpToAgreementH5WithString:@"yhxy"]; 36 +// [CNLiveUserAgreementManager jumpToAgreementH5WithType:CNLiveUserAgreementHelp];
  37 + [CNLiveUserAgreementManager jumpToAgreementH5WithString:@"yhxy"];
38 38
39 } 39 }
40 40