123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- //
- // KXWebDetailViewController.m
- // QBCS
- //
- // Created by kuxuan on 2017/6/8.
- // Copyright © 2017年 kuxuan. All rights reserved.
- //
- #import "KXWebDetailViewController.h"
- #import "KXThirdMarkView.h"
- @interface KXWebDetailViewController ()<UIWebViewDelegate,KXThirdMarkViewDelegate>
- {
- UIWebView *_webView;
- KXThirdMarkView *_thirdMarkView;
- }
- @property (nonatomic,strong)MBProgressHUD *hud;
- @end
- @implementation KXWebDetailViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- NSDate *date = [[NSUserDefaults standardUserDefaults]objectForKey:KXMARK_TODAY];
- if (!date) {
- [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"mark"];
- [[NSUserDefaults standardUserDefaults]synchronize];
- }
- [self createNavigation];
- [self loadingWebView];
- [self updateApplyStatus:@"2"];
- [self checkMarkView];
- }
- -(void)createNavigation
- {
- self.name=self.titleStr;
-
- [self addLeftBarButtonItemWithImageName:@"main_back" title:nil target:self selector:@selector(backAction)];
-
- }
- - (void)checkMarkView
- {
- NSDate *date = [[NSUserDefaults standardUserDefaults]objectForKey:KXMARK_TODAY];
- NSTimeInterval timeInterval = [[NSDate date] timeIntervalSinceDate:date];
- // 3.0的处理逻辑
- NSInteger clickCount = [[NSUserDefaults standardUserDefaults] integerForKey:KXMARK_CLICKCOUNT];
- BOOL isMark = [[NSUserDefaults standardUserDefaults] boolForKey:KXMARK_TOAPPSTORE];
- if (isMark == YES) {
- if (timeInterval > 10*24*60*60) {
- if (clickCount >3 && clickCount%4 == 0) {
- [self createThirdMarkView];
- }
- }
- } else{
- if (!date) {
- if (clickCount >3 && clickCount%4==0) {
- [self createThirdMarkView];
- }
- }
- if (timeInterval > 3*24*60*60) {
- if (clickCount >3 && clickCount%4==0) {
- [self createThirdMarkView];
- }
- }
- }
-
- }
- - (void)createThirdMarkView{
- if (!_thirdMarkView) {
- _thirdMarkView = [[KXThirdMarkView alloc] initWithFrame:[UIScreen mainScreen].bounds];
- _thirdMarkView.delegate = self;
- [[UIApplication sharedApplication].keyWindow addSubview:_thirdMarkView];
- }
- }
- #pragma mark ===================KXThirdMarkVIewDelegate==============
- - (void)markViewBtnClick:(UIButton *)button{
- switch (button.tag) {
- case 1000: //跳转按钮
- {
- [MobClick event:@"appstoreCommentClick"];
- [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:KXMARK_TODAY];
- [[NSUserDefaults standardUserDefaults] setBool:YES forKey:KXMARK_TOAPPSTORE];
- [[NSUserDefaults standardUserDefaults] synchronize];
- if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:KXAPPSTORE_ADDRESS]]) {
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:KXAPPSTORE_ADDRESS]];
- [_thirdMarkView removeFromSuperview];
- }
- }
- break;
- case 2000: //关闭按钮
- {
- [MobClick event:@"appstoreCommentClose"];
- [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:KXMARK_TODAY];
- [[NSUserDefaults standardUserDefaults] setBool:NO forKey:KXMARK_TOAPPSTORE];
- [[NSUserDefaults standardUserDefaults] synchronize];
- [_thirdMarkView removeFromSuperview];
- }
- break;
- default:
- break;
- }
- }
- -(void)backAction
- {
- [self.navigationController popViewControllerAnimated:YES];
- }
- -(void)closeAction
- {
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"本次是否完成申请" preferredStyle:UIAlertControllerStyleAlert];
- [alertController addAction:[UIAlertAction actionWithTitle:@"已申请" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- [self updateApplyStatus:@"3"];
- [self.navigationController popToRootViewControllerAnimated:YES];
- }]];
- [alertController addAction:[UIAlertAction actionWithTitle:@"只是看看" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
- [self updateApplyStatus:@"2"];
- [self.navigationController popToRootViewControllerAnimated:YES];
- }]];
- [self presentViewController:alertController animated:YES completion:nil];
- }
- /**
- 更改产品的状态
- @param status 1为我的足迹 3为我的申请 2.只是看看
- */
- - (void)updateApplyStatus:(NSString *)status
- {
- NSString *statusString = [NSString stringWithFormat:@"%@/user/updateApplyStatus",URL];
- 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};
- [KXHTTP post:statusString params:paraDict success:^(id json) {
-
- } failure:^(NSError *error) {
-
- }];
- }
- -(void)loadingWebView
- {
- _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64)];
- _webView.delegate=self;
- _webView.scalesPageToFit=YES;
- if (self.webStr) {
- [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.webStr]]];
- }else{
- [_webView loadHTMLString:self.html baseURL:nil];
- }
- [self.view addSubview:_webView];
- }
- #pragma UIWebViewDelegate
- - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
- navigationType:(UIWebViewNavigationType)navigationType
- {
- if (navigationType==UIWebViewNavigationTypeBackForward) {
- _webView.canGoBack?[_webView goBack]:[self.navigationController popViewControllerAnimated:YES];
- }
- return YES;
- }
- - (void)webViewDidStartLoad:(UIWebView *)webView
- {
- NSLog(@"开始加载");
-
-
-
- //[self.hud showAnimated:YES];
- }
- - (void)webViewDidFinishLoad:(UIWebView *)webView
- {
- if (webView.isLoading) {
- return;
- }
- //[self.hud hideAnimated:YES];
- NSLog(@"结束加载");
-
- }
- - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
- {
- //[self.hud hideAnimated:YES];
- NSLog(@"加载失败");
- // if (webView.request.URL.absoluteString.length ) {
- // [_webView reload];
- // }
- }
- -(MBProgressHUD *)hud
- {
- if (!_hud) {
- _hud=[[MBProgressHUD alloc]initWithView:self.view];
- _hud.labelText=@"加载中...";
- [self.view addSubview:_hud];
- }
- return _hud;
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|