Commit d15b300000d6802336dd1555050f9f86ffad31c6

Authored by 梁星国
1 parent 43535289

提交0.0.14_添加web加载问题和输入框和其他人使用了同一通知

CNLiveOrganizationValidationModule.podspec
@@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
8 8
9 Pod::Spec.new do |s| 9 Pod::Spec.new do |s|
10 s.name = 'CNLiveOrganizationValidationModule' 10 s.name = 'CNLiveOrganizationValidationModule'
11 - s.version = '0.0.13' 11 + s.version = '0.0.14'
12 s.summary = '机构认证模块' 12 s.summary = '机构认证模块'
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.
CNLiveOrganizationValidationModule/Classes/CNLiveOrganizationValidationModule/Controller/CNLiveBAgreementContentController.m
@@ -23,18 +23,30 @@ @@ -23,18 +23,30 @@
23 #define CNLiveBOrganizationContentAgreementUrl cn_API_Refund(@"/term/cnBNraqxy.html") 23 #define CNLiveBOrganizationContentAgreementUrl cn_API_Refund(@"/term/cnBNraqxy.html")
24 @interface CNLiveBAgreementContentController ()<WKNavigationDelegate,WKUIDelegate,UIScrollViewDelegate> 24 @interface CNLiveBAgreementContentController ()<WKNavigationDelegate,WKUIDelegate,UIScrollViewDelegate>
25 25
  26 +@property (strong, nonatomic) NSString *url;
  27 +
26 @property (strong, nonatomic) WKWebView *wkwebView; 28 @property (strong, nonatomic) WKWebView *wkwebView;
27 29
28 -@property (strong, nonatomic) NSString *url; 30 +@property (assign,nonatomic) NSUInteger loadCount;
  31 +@property (assign,nonatomic) UIProgressView *progressView;
  32 +
29 33
30 @end 34 @end
31 35
32 @implementation CNLiveBAgreementContentController 36 @implementation CNLiveBAgreementContentController
33 37
  38 +- (void)dealloc
  39 +{
  40 + if (self.wkwebView && self) {
  41 + [self.wkwebView removeObserver:self forKeyPath:@"estimatedProgress"];
  42 + }
  43 +}
  44 +
34 - (void)viewDidLoad { 45 - (void)viewDidLoad {
35 [super viewDidLoad]; 46 [super viewDidLoad];
36 self.title = @"机构认证"; 47 self.title = @"机构认证";
37 [self.view setBackgroundColor:[UIColor whiteColor]]; 48 [self.view setBackgroundColor:[UIColor whiteColor]];
  49 + self.url = CNLiveBOrganizationContentAgreementUrl;
38 [self initWKWebView]; 50 [self initWKWebView];
39 51
40 52
@@ -42,17 +54,81 @@ @@ -42,17 +54,81 @@
42 54
43 -(void)initWKWebView 55 -(void)initWKWebView
44 { 56 {
  57 +
  58 + UIProgressView *progress = [[UIProgressView alloc]initWithFrame:CGRectMake(0, kNavigationBarHeight, KScreenWidth, 1)];
  59 + progress.tintColor = RGBOF(0x389FEF);
  60 + progress.trackTintColor = [UIColor whiteColor];
  61 + [self.view addSubview:progress];
  62 + self.progressView = progress;
  63 +
  64 +
45 self.view.backgroundColor = [UIColor whiteColor]; 65 self.view.backgroundColor = [UIColor whiteColor];
46 - self.url = CNLiveBOrganizationContentAgreementUrl;  
47 - WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, KScreenHeight)];  
48 - self.view = webView;  
49 - NSURL *url = [NSURL URLWithString:self.url];  
50 - NSURLRequest *request = [NSURLRequest requestWithURL:url];  
51 - [webView loadRequest:request]; 66 + WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, kNavigationBarHeight, kScreenWidth, KScreenHeight - kNavigationBarHeight)];
  67 + [self.view addSubview:webView];
  68 + webView.UIDelegate = self;
  69 + webView.navigationDelegate = self;
  70 + webView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
  71 + [webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
  72 + if (self.url) {
  73 + NSURL *url = [NSURL URLWithString:self.url];
  74 + if (url) {
  75 + NSURLRequest *request = [NSURLRequest requestWithURL:url];
  76 + [webView loadRequest:request];
  77 + }
  78 + }
  79 + [self.view insertSubview:webView belowSubview:progress];
  80 + self.wkwebView = webView;
  81 +
  82 + self.extendedLayoutIncludesOpaqueBars = YES;
  83 + if (@available(iOS 11.0, *)) {
  84 + self.wkwebView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  85 + } else {
  86 + self.automaticallyAdjustsScrollViewInsets = NO;
  87 + }
  88 +
  89 +}
52 90
  91 +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
53 92
  93 + if ([keyPath isEqualToString:@"estimatedProgress"]) {
  94 + CGFloat newProgress = [[change objectForKey:NSKeyValueChangeNewKey] doubleValue];
  95 + if (newProgress == 1) {
  96 + if (self) {
  97 + self.progressView.hidden = YES;
  98 + [self.progressView setProgress:0 animated:NO];
  99 + }
  100 +
  101 + }else{
  102 + if (self) {
  103 + self.progressView.hidden = NO;
  104 + [self.progressView setProgress:newProgress animated:YES];
  105 + }
  106 +
  107 + }
  108 + }
54 } 109 }
55 110
  111 +- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler{
  112 + // 在发送请求之前,决定是否跳转
  113 + decisionHandler(WKNavigationActionPolicyAllow);
  114 +
  115 +}
  116 +
  117 + // 页面开始加载时调用
  118 +- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {
  119 +}
  120 + // 页面加载失败时调用
  121 +- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error {
  122 + if (self) {
  123 + [self.progressView setProgress:0.0f animated:NO];
  124 + [QMUITips showError:@"加载失败,请检查网络" inView:self.view hideAfterDelay:0.5];
  125 + }
  126 +
  127 +
  128 +
  129 +}
  130 +
  131 +
56 132
57 133
58 134
CNLiveOrganizationValidationModule/Classes/CNLiveOrganizationValidationModule/Controller/CNLiveBWebViewController.m
@@ -30,6 +30,13 @@ @@ -30,6 +30,13 @@
30 30
31 @implementation CNLiveBWebViewController 31 @implementation CNLiveBWebViewController
32 32
  33 +- (void)dealloc
  34 +{
  35 + if (self.wkwebView && self) {
  36 + [self.wkwebView removeObserver:self forKeyPath:@"estimatedProgress"];
  37 + }
  38 +}
  39 +
33 - (void)viewDidLoad { 40 - (void)viewDidLoad {
34 [super viewDidLoad]; 41 [super viewDidLoad];
35 [self.view setBackgroundColor:[UIColor whiteColor]]; 42 [self.view setBackgroundColor:[UIColor whiteColor]];
@@ -51,6 +58,8 @@ @@ -51,6 +58,8 @@
51 self.view.backgroundColor = [UIColor whiteColor]; 58 self.view.backgroundColor = [UIColor whiteColor];
52 WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, KScreenHeight)]; 59 WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, KScreenHeight)];
53 [self.view addSubview:webView]; 60 [self.view addSubview:webView];
  61 + webView.UIDelegate = self;
  62 + webView.navigationDelegate = self;
54 webView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; 63 webView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
55 [webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil]; 64 [webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
56 if (self.url) { 65 if (self.url) {
@@ -62,6 +71,15 @@ @@ -62,6 +71,15 @@
62 } 71 }
63 [self.view insertSubview:webView belowSubview:progress]; 72 [self.view insertSubview:webView belowSubview:progress];
64 73
  74 + self.wkwebView = webView;
  75 +
  76 + self.extendedLayoutIncludesOpaqueBars = YES;
  77 + if (@available(iOS 11.0, *)) {
  78 + self.wkwebView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  79 + } else {
  80 + self.automaticallyAdjustsScrollViewInsets = NO;
  81 + }
  82 +
65 } 83 }
66 84
67 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{ 85 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
@@ -69,11 +87,17 @@ @@ -69,11 +87,17 @@
69 if ([keyPath isEqualToString:@"estimatedProgress"]) { 87 if ([keyPath isEqualToString:@"estimatedProgress"]) {
70 CGFloat newProgress = [[change objectForKey:NSKeyValueChangeNewKey] doubleValue]; 88 CGFloat newProgress = [[change objectForKey:NSKeyValueChangeNewKey] doubleValue];
71 if (newProgress == 1) { 89 if (newProgress == 1) {
72 - self.progressView.hidden = YES;  
73 - [self.progressView setProgress:0 animated:NO]; 90 + if (self) {
  91 + self.progressView.hidden = YES;
  92 + [self.progressView setProgress:0 animated:NO];
  93 + }
  94 +
74 }else{ 95 }else{
75 - self.progressView.hidden = NO;  
76 - [self.progressView setProgress:newProgress animated:YES]; 96 + if (self) {
  97 + self.progressView.hidden = NO;
  98 + [self.progressView setProgress:newProgress animated:YES];
  99 + }
  100 +
77 } 101 }
78 } 102 }
79 } 103 }
@@ -82,9 +106,21 @@ @@ -82,9 +106,21 @@
82 // 在发送请求之前,决定是否跳转 106 // 在发送请求之前,决定是否跳转
83 decisionHandler(WKNavigationActionPolicyAllow); 107 decisionHandler(WKNavigationActionPolicyAllow);
84 108
85 -  
86 } 109 }
87 110
  111 + // 页面开始加载时调用
  112 +- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {
  113 +}
  114 + // 页面加载失败时调用
  115 +- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error {
  116 + if (self) {
  117 + [self.progressView setProgress:0.0f animated:NO];
  118 + [QMUITips showError:@"加载失败,请检查网络" inView:self.view hideAfterDelay:0.5];
  119 + }
  120 +
  121 +
  122 +
  123 +}
88 124
89 125
90 126
CNLiveOrganizationValidationModule/Classes/CNLiveOrganizationValidationModule/View/CNLiveBOrganizationContentCell.m
@@ -28,6 +28,9 @@ @@ -28,6 +28,9 @@
28 28
29 @implementation CNLiveBOrganizationTFCell 29 @implementation CNLiveBOrganizationTFCell
30 30
  31 +-(void)dealloc {
  32 +
  33 +}
31 34
32 - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 35 - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
33 { 36 {
@@ -61,7 +64,7 @@ @@ -61,7 +64,7 @@
61 [self addSubview:self.contentL]; 64 [self addSubview:self.contentL];
62 self.selectionStyle = UITableViewCellSelectionStyleNone; 65 self.selectionStyle = UITableViewCellSelectionStyleNone;
63 66
64 - [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textFieldTextChange:) name:UITextFieldTextDidChangeNotification object:nil]; 67 + [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(cnLiveBTextFieldTextDidChange:) name:UITextFieldTextDidChangeNotification object:nil];
65 68
66 self.tipImageV.frame = CGRectMake(10, 18 , 7, 8); 69 self.tipImageV.frame = CGRectMake(10, 18 , 7, 8);
67 self.tipImageV.image = [UIImage imageNamedFromOrganization:@"organization_must"]; 70 self.tipImageV.image = [UIImage imageNamedFromOrganization:@"organization_must"];
@@ -180,7 +183,7 @@ @@ -180,7 +183,7 @@
180 183
181 184
182 #pragma mark - ***监听实现*** 185 #pragma mark - ***监听实现***
183 -- (void)textFieldTextChange:(NSNotification *)notification{ 186 +- (void)cnLiveBTextFieldTextDidChange:(NSNotification *)notification{
184 CNLiveBOrganizationTextField *textField = (CNLiveBOrganizationTextField *)notification.object; 187 CNLiveBOrganizationTextField *textField = (CNLiveBOrganizationTextField *)notification.object;
185 if (textField) { 188 if (textField) {
186 if (textField.contentLengthMax == 0) { 189 if (textField.contentLengthMax == 0) {
@@ -293,6 +296,11 @@ @@ -293,6 +296,11 @@
293 @implementation CNLiveBOrganizationTViewCell 296 @implementation CNLiveBOrganizationTViewCell
294 297
295 298
  299 +- (void)dealloc
  300 +{
  301 +
  302 +}
  303 +
296 - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 304 - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
297 { 305 {
298 self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 306 self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
@@ -328,7 +336,7 @@ @@ -328,7 +336,7 @@
328 self.titleL.frame = CGRectMake(21.5, 16, 72, 12); 336 self.titleL.frame = CGRectMake(21.5, 16, 72, 12);
329 self.contentTV.frame = CGRectMake(104.5, 10, KScreenWidth - 104.5 - 30.5, 78); 337 self.contentTV.frame = CGRectMake(104.5, 10, KScreenWidth - 104.5 - 30.5, 78);
330 338
331 - [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textViewTextChange:) name:UITextViewTextDidChangeNotification object:nil]; 339 + [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(cnliveBTextViewTextChange:) name:UITextViewTextDidChangeNotification object:nil];
332 340
333 } 341 }
334 342
@@ -369,7 +377,7 @@ @@ -369,7 +377,7 @@
369 #pragma mark - ***事件实现*** 377 #pragma mark - ***事件实现***
370 378
371 #pragma mark - ***监听实现*** 379 #pragma mark - ***监听实现***
372 -- (void)textViewTextChange:(NSNotification *)notification{ 380 +- (void)cnliveBTextViewTextChange:(NSNotification *)notification{
373 CNLiveBOrganizationTextView *textView = (CNLiveBOrganizationTextView *)notification.object; 381 CNLiveBOrganizationTextView *textView = (CNLiveBOrganizationTextView *)notification.object;
374 if (textView) { 382 if (textView) {
375 if (textView.contentLengthMax == 0) { 383 if (textView.contentLengthMax == 0) {