YBDestroySureVC.m 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. //
  2. // YBDestroySureVC.m
  3. // YBVideo
  4. //
  5. // Created by YB007 on 2020/6/22.
  6. // Copyright © 2020 cat. All rights reserved.
  7. //
  8. #import "YBDestroySureVC.h"
  9. #import <WebKit/WebKit.h>
  10. #import "YBTabBarController.h"
  11. @interface YBDestroySureVC ()<WKNavigationDelegate>
  12. {
  13. UIView *_shadowView;
  14. }
  15. @property(nonatomic,strong)WKWebView *webView;
  16. @property (nonatomic,strong) CALayer *progresslayer;
  17. @property(nonatomic,strong)UIButton *suerBtn;
  18. @property(nonatomic,strong)UIButton *cancleBtn;
  19. @end
  20. @implementation YBDestroySureVC
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. self.titleL.text = YZMsg(@"注销账号");
  24. self.webView = [[WKWebView alloc] init];
  25. self.webView.navigationDelegate = self;
  26. _webView.backgroundColor = Normal_Color;
  27. [self.view addSubview:self.webView];
  28. self.progresslayer = [[CALayer alloc]init];
  29. self.progresslayer.frame = CGRectMake(0, 0, _window_width*0.1, 2);
  30. self.progresslayer.backgroundColor = Pink_Cor.CGColor;
  31. [self.webView.layer addSublayer:self.progresslayer];
  32. [self.webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
  33. [self.webView addObserver:self forKeyPath:@"title" options:NSKeyValueObservingOptionNew context:NULL];
  34. NSString *url = [h5url stringByAppendingFormat:@"/portal/page/index/?id=151"];
  35. url = [url stringByAppendingFormat:@"&lang=%@",[YBLanguageTools serviceLang]];
  36. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
  37. _shadowView = [[UIView alloc]init];
  38. _shadowView.backgroundColor = Normal_Color;
  39. [self.view addSubview:_shadowView];
  40. [self.view addSubview:self.suerBtn];
  41. [_suerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.width.equalTo(self.view.mas_width).multipliedBy(0.4);
  43. make.centerX.equalTo(self.view.mas_centerX).multipliedBy(0.5);
  44. make.height.mas_equalTo(40);
  45. make.bottom.equalTo(self.view.mas_bottom).offset(-ShowDiff-20);
  46. }];
  47. [self.view addSubview:self.cancleBtn];
  48. [_cancleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.width.height.centerY.equalTo(_suerBtn);
  50. make.centerX.equalTo(self.view.mas_centerX).multipliedBy(1.5);
  51. }];
  52. [_webView mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.width.centerX.equalTo(self.view);
  54. make.top.equalTo(self.naviView.mas_bottom);
  55. make.bottom.equalTo(_suerBtn.mas_top).offset(-10);
  56. }];
  57. [_shadowView mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.width.height.centerY.centerX.equalTo(_webView);
  59. }];
  60. }
  61. - (UIButton *)suerBtn {
  62. if (!_suerBtn) {
  63. _suerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  64. [_suerBtn setTitleColor:Pink_Cor forState:0];
  65. _suerBtn.titleLabel.font = SYS_Font(15);
  66. [_suerBtn setTitle:YZMsg(@"确认注销") forState:0];
  67. _suerBtn.layer.cornerRadius = 20;
  68. _suerBtn.layer.masksToBounds = YES;
  69. _suerBtn.layer.borderColor = Pink_Cor.CGColor;
  70. _suerBtn.layer.borderWidth = 1;
  71. [_suerBtn addTarget:self action:@selector(clikcSureBtn) forControlEvents:UIControlEventTouchUpInside];
  72. }
  73. return _suerBtn;
  74. }
  75. -(void)clikcSureBtn {
  76. NSDictionary *contentDic = @{@"title":YZMsg(@"提示"),
  77. @"msg":YZMsg(@"点击确认注销后,账号将立即注销"),
  78. @"left":YZMsg(@"取消"),
  79. @"right":YZMsg(@"确认"),
  80. };
  81. YBWeakSelf;
  82. YBAlertView *alertView = [YBAlertView showAlertView:contentDic complete:^(int eventType) {
  83. if (eventType == 1) {
  84. [weakSelf sureDestroy];
  85. }
  86. }];
  87. [alertView.sureBtn setTitleColor:RGB_COLOR(@"#593FB0", 1) forState:0];
  88. [alertView.cancleBtn setTitleColor:RGB_COLOR(@"#000000", 1) forState:0];
  89. }
  90. - (NSString *)currentTimeStamp {
  91. NSDate *datenow = [NSDate date];
  92. NSString *timeStamp = [NSString stringWithFormat:@"%ld", (long)([datenow timeIntervalSince1970]*1000)];
  93. return timeStamp;
  94. }
  95. -(void)sureDestroy {
  96. NSMutableDictionary *mudic = @{
  97. @"uid":[Config getOwnID],
  98. @"token":[Config getOwnToken],
  99. @"time":[self currentTimeStamp],
  100. }.mutableCopy;
  101. [mudic setObject:[PublicObj sortString:mudic] forKey:@"sign"];
  102. YBWeakSelf;
  103. [MBProgressHUD showMessage:@""];
  104. [YBNetworking postWithUrl:@"Login.cancelAccount" Dic:mudic Suc:^(int code, id info, NSString *msg) {
  105. [MBProgressHUD hideHUD];
  106. [MBProgressHUD showPop:msg];
  107. if (code == 0) {
  108. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  109. [weakSelf quitLogin];
  110. });
  111. }
  112. } Fail:^(id fail) {
  113. [MBProgressHUD hideHUD];
  114. }];
  115. }
  116. -(void)quitLogin{
  117. [PublicObj resetUserToVisitor];
  118. YBTabBarController *root = [[YBTabBarController alloc]initWithAlert:NO];
  119. YBNavigationController *navroot = [[YBNavigationController alloc]initWithRootViewController:root];
  120. UIApplication *app =[UIApplication sharedApplication];
  121. AppDelegate *app2 = (AppDelegate*)app.delegate;
  122. [app2.window removeAllSubViews];
  123. app2.window.rootViewController = navroot;
  124. }
  125. - (UIButton *)cancleBtn {
  126. if (!_cancleBtn) {
  127. _cancleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  128. [_cancleBtn setTitleColor:RGB_COLOR(@"#ffffff", 1) forState:0];
  129. _cancleBtn.titleLabel.font = SYS_Font(15);
  130. [_cancleBtn setTitle:YZMsg(@"取消") forState:0];
  131. _cancleBtn.backgroundColor = Pink_Cor;
  132. _cancleBtn.layer.cornerRadius = 20;
  133. _cancleBtn.layer.masksToBounds = YES;
  134. [_cancleBtn addTarget:self action:@selector(clikcCancleBtn) forControlEvents:UIControlEventTouchUpInside];
  135. }
  136. return _cancleBtn;
  137. }
  138. -(void)clikcCancleBtn {
  139. [[YBBaseAppDelegate sharedAppDelegate]popViewController:YES];
  140. }
  141. // 观察者
  142. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
  143. if ([keyPath isEqualToString:@"estimatedProgress"]) {
  144. self.progresslayer.opacity = 1;
  145. float floatNum = [[change objectForKey:@"new"] floatValue];
  146. self.progresslayer.frame = CGRectMake(0, 0, _window_width*floatNum, 2);
  147. if (floatNum == 1) {
  148. __weak __typeof(self)weakSelf = self;
  149. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  150. weakSelf.progresslayer.opacity = 0;
  151. });
  152. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  153. weakSelf.progresslayer.frame = CGRectMake(0, 0, 0, 3);
  154. _shadowView.hidden = YES;
  155. });
  156. }
  157. }else if ([keyPath isEqualToString:@"title"]){//网页title
  158. if (object == self.webView){
  159. self.titleL.text = self.webView.title;
  160. }else{
  161. [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
  162. }
  163. }else{
  164. [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
  165. }
  166. }
  167. - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler{
  168. NSString *url = navigationAction.request.URL.absoluteString;
  169. if (navigationAction.targetFrame.isMainFrame) {
  170. NSLog(@"target is main ... %@",url);
  171. if (navigationAction.sourceFrame.mainFrame) {
  172. NSLog(@"source is main...%@",url);
  173. if ([url containsString:@"tel:"]) {
  174. [[UIApplication sharedApplication]openURL:[NSURL URLWithString:url]];
  175. decisionHandler(WKNavigationActionPolicyCancel);
  176. return;
  177. }
  178. } else {
  179. NSLog(@"source is not main...%@",url);
  180. }
  181. } else {
  182. NSLog(@"target is not main ... %@",url);
  183. }
  184. decisionHandler(WKNavigationActionPolicyAllow);
  185. NSLog(@"在发送请求之前:%@",navigationAction.request.URL.absoluteString);
  186. }
  187. -(void)dealloc{
  188. [self.webView removeObserver:self forKeyPath:@"estimatedProgress"];
  189. [self.webView removeObserver:self forKeyPath:@"title"];
  190. }
  191. @end