No Description

KXWebDetailViewController.m 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. //
  2. // KXWebDetailViewController.m
  3. // QBCS
  4. //
  5. // Created by kuxuan on 2017/6/8.
  6. // Copyright © 2017年 kuxuan. All rights reserved.
  7. //
  8. #import "KXWebDetailViewController.h"
  9. #import "KXThirdMarkView.h"
  10. @interface KXWebDetailViewController ()<UIWebViewDelegate,KXThirdMarkViewDelegate>
  11. {
  12. UIWebView *_webView;
  13. KXThirdMarkView *_thirdMarkView;
  14. }
  15. @property (nonatomic,strong)MBProgressHUD *hud;
  16. @end
  17. @implementation KXWebDetailViewController
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. // Do any additional setup after loading the view.
  21. NSDate *date = [[NSUserDefaults standardUserDefaults]objectForKey:KXMARK_TODAY];
  22. if (!date) {
  23. [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"mark"];
  24. [[NSUserDefaults standardUserDefaults]synchronize];
  25. }
  26. [self createNavigation];
  27. [self loadingWebView];
  28. [self updateApplyStatus:@"2"];
  29. [self checkMarkView];
  30. }
  31. -(void)createNavigation
  32. {
  33. self.name=self.titleStr;
  34. [self addLeftBarButtonItemWithImageName:@"main_back" title:nil target:self selector:@selector(backAction)];
  35. }
  36. - (void)checkMarkView
  37. {
  38. NSDate *date = [[NSUserDefaults standardUserDefaults]objectForKey:KXMARK_TODAY];
  39. NSTimeInterval timeInterval = [[NSDate date] timeIntervalSinceDate:date];
  40. // 3.0的处理逻辑
  41. NSInteger clickCount = [[NSUserDefaults standardUserDefaults] integerForKey:KXMARK_CLICKCOUNT];
  42. BOOL isMark = [[NSUserDefaults standardUserDefaults] boolForKey:KXMARK_TOAPPSTORE];
  43. if (isMark == YES) {
  44. if (timeInterval > 10*24*60*60) {
  45. if (clickCount >3 && clickCount%4 == 0) {
  46. [self createThirdMarkView];
  47. }
  48. }
  49. } else{
  50. if (!date) {
  51. if (clickCount >3 && clickCount%4==0) {
  52. [self createThirdMarkView];
  53. }
  54. }
  55. if (timeInterval > 3*24*60*60) {
  56. if (clickCount >3 && clickCount%4==0) {
  57. [self createThirdMarkView];
  58. }
  59. }
  60. }
  61. }
  62. - (void)createThirdMarkView{
  63. if (!_thirdMarkView) {
  64. _thirdMarkView = [[KXThirdMarkView alloc] initWithFrame:[UIScreen mainScreen].bounds];
  65. _thirdMarkView.delegate = self;
  66. [[UIApplication sharedApplication].keyWindow addSubview:_thirdMarkView];
  67. }
  68. }
  69. #pragma mark ===================KXThirdMarkVIewDelegate==============
  70. - (void)markViewBtnClick:(UIButton *)button{
  71. switch (button.tag) {
  72. case 1000: //跳转按钮
  73. {
  74. [MobClick event:@"appstoreCommentClick"];
  75. [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:KXMARK_TODAY];
  76. [[NSUserDefaults standardUserDefaults] setBool:YES forKey:KXMARK_TOAPPSTORE];
  77. [[NSUserDefaults standardUserDefaults] synchronize];
  78. if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:KXAPPSTORE_ADDRESS]]) {
  79. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:KXAPPSTORE_ADDRESS]];
  80. [_thirdMarkView removeFromSuperview];
  81. }
  82. }
  83. break;
  84. case 2000: //关闭按钮
  85. {
  86. [MobClick event:@"appstoreCommentClose"];
  87. [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:KXMARK_TODAY];
  88. [[NSUserDefaults standardUserDefaults] setBool:NO forKey:KXMARK_TOAPPSTORE];
  89. [[NSUserDefaults standardUserDefaults] synchronize];
  90. [_thirdMarkView removeFromSuperview];
  91. }
  92. break;
  93. default:
  94. break;
  95. }
  96. }
  97. -(void)backAction
  98. {
  99. [self.navigationController popViewControllerAnimated:YES];
  100. }
  101. -(void)closeAction
  102. {
  103. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"本次是否完成申请" preferredStyle:UIAlertControllerStyleAlert];
  104. [alertController addAction:[UIAlertAction actionWithTitle:@"已申请" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  105. [self updateApplyStatus:@"3"];
  106. [self.navigationController popToRootViewControllerAnimated:YES];
  107. }]];
  108. [alertController addAction:[UIAlertAction actionWithTitle:@"只是看看" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  109. [self updateApplyStatus:@"2"];
  110. [self.navigationController popToRootViewControllerAnimated:YES];
  111. }]];
  112. [self presentViewController:alertController animated:YES completion:nil];
  113. }
  114. /**
  115. 更改产品的状态
  116. @param status 1为我的足迹 3为我的申请 2.只是看看
  117. */
  118. - (void)updateApplyStatus:(NSString *)status
  119. {
  120. NSString *statusString = [NSString stringWithFormat:@"%@/user/updateApplyStatus",URL];
  121. NSDictionary *paraDict = @{@"product_apply_id":self.product_apply_id,@"status":status,@"skip_type":[self.product_apply_id isEqualToString:@"0"]?@"1":@"0",@"product_id":self.product_id};
  122. [KXHTTP post:statusString params:paraDict success:^(id json) {
  123. } failure:^(NSError *error) {
  124. }];
  125. }
  126. -(void)loadingWebView
  127. {
  128. _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64)];
  129. _webView.delegate=self;
  130. _webView.scalesPageToFit=YES;
  131. if (self.webStr) {
  132. [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.webStr]]];
  133. }else{
  134. [_webView loadHTMLString:self.html baseURL:nil];
  135. }
  136. [self.view addSubview:_webView];
  137. }
  138. #pragma UIWebViewDelegate
  139. - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
  140. navigationType:(UIWebViewNavigationType)navigationType
  141. {
  142. if (navigationType==UIWebViewNavigationTypeBackForward) {
  143. _webView.canGoBack?[_webView goBack]:[self.navigationController popViewControllerAnimated:YES];
  144. }
  145. return YES;
  146. }
  147. - (void)webViewDidStartLoad:(UIWebView *)webView
  148. {
  149. NSLog(@"开始加载");
  150. //[self.hud showAnimated:YES];
  151. }
  152. - (void)webViewDidFinishLoad:(UIWebView *)webView
  153. {
  154. if (webView.isLoading) {
  155. return;
  156. }
  157. //[self.hud hideAnimated:YES];
  158. NSLog(@"结束加载");
  159. }
  160. - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
  161. {
  162. //[self.hud hideAnimated:YES];
  163. NSLog(@"加载失败");
  164. // if (webView.request.URL.absoluteString.length ) {
  165. // [_webView reload];
  166. // }
  167. }
  168. -(MBProgressHUD *)hud
  169. {
  170. if (!_hud) {
  171. _hud=[[MBProgressHUD alloc]initWithView:self.view];
  172. _hud.labelText=@"加载中...";
  173. [self.view addSubview:_hud];
  174. }
  175. return _hud;
  176. }
  177. - (void)didReceiveMemoryWarning {
  178. [super didReceiveMemoryWarning];
  179. // Dispose of any resources that can be recreated.
  180. }
  181. /*
  182. #pragma mark - Navigation
  183. // In a storyboard-based application, you will often want to do a little preparation before navigation
  184. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  185. // Get the new view controller using [segue destinationViewController].
  186. // Pass the selected object to the new view controller.
  187. }
  188. */
  189. @end