//
//  LittleGoldHouseWebVC.m
//  Open
//
//  Created by 雷俊博 on 2021/4/15.
//  Copyright © 2021 黄江涛 . All rights reserved.
//

#import "LittleGoldHouseWebVC.h"
#import <WebKit/WebKit.h>
#import "WeakWebViewScriptMessageDelegate.h"
#import "Tools.h"

//认证查询
#import "WeiJianQueryViewController.h"
//我的奖品
#import "MyPrizeListVC.h"


//弹框
#import "KKGoldHouseActivityView.h"
#import "KKSaveBankRedPackageOPenedView.h"



@interface LittleGoldHouseWebVC ()<WKUIDelegate,WKNavigationDelegate,WKScriptMessageHandler>
{
    BOOL loadSuccess;
}

@property (nonatomic, strong)WKWebView *webView;

@property (nonatomic, strong)UILabel *lb_content;

@property (strong, nonatomic)  dispatch_source_t timer;

@property (nonatomic,assign)BOOL isPause;

@property (nonatomic, assign)BOOL isDestoryTimer;

@property (nonatomic, strong)UIButton *taskBtn;


@end

@implementation LittleGoldHouseWebVC

- (void)dealloc {
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
    
    
    NSLog(@"页面已销毁");
    
    if (_timer) {
        if (self.isDestoryTimer == NO) {
            dispatch_source_cancel(_timer);
            self.isDestoryTimer = YES;
        }
        
    }
//    dispatch_suspend(_timer);
//
//    dispatch_source_cancel(_timer);
//
    _timer =nil;// OK
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    
    [self.navigationController.navigationBar navBarBackGroundColor:[UIColor colorWithHex:0xcb8b4d] image:nil isOpaque:YES];//颜色
    
    [self.navigationController.navigationBar navBarBottomLineHidden:YES];
    
         
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIView *whiteView = [[UIView alloc]initWithFrame:self.view.bounds];
    [self.view addSubview:whiteView];
    [whiteView addSubview:self.webView];

    

    
    if (@available(iOS 11.0, *)) {
           self.webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
       } else {
           self.automaticallyAdjustsScrollViewInsets = NO;
       }
    
    //[self configNav];
    [self navConfig];
    
    [self requestUrlFromServe];
    

    
    //显示活动弹框
    
    
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
    
    
}



- (void)configNav
{
    UIButton* backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setTitle:@"返回" forState:UIControlStateNormal];
    [backBtn setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    [backBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    backBtn.frame = CGRectMake(0, 0, 60, 44);
    [backBtn layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleLeft imageTitleSpace:8];
    [backBtn addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem*backItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
    
    self.navigationItem.leftBarButtonItem = backItem;
        
    
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightBtn setTitle:@"邀请有礼" forState:UIControlStateNormal];
    [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [rightBtn addTarget:self action:@selector(rightBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
    
    self.navigationItem.rightBarButtonItem = rightItem;
    
}


- (void)navConfig
{
    UIView*navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, cl_kNavigationBarHeight)];
    navView.backgroundColor = [UIColor colorWithHex:0xcb8b4d];
    [self.view addSubview:navView];
    
    UIButton * backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake( 10 * WIDTHRADIU, cl_kStatusBarHeight + 9.5, 50, 25);
    backBtn.titleLabel.textAlignment =NSTextAlignmentLeft;
    [backBtn setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    [backBtn setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateHighlighted];
    [backBtn setTitle:@"返回" forState:UIControlStateNormal];
    [backBtn setTitle:@"返回" forState:UIControlStateHighlighted];
    [backBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [backBtn layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleLeft imageTitleSpace:4];
    [backBtn addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
    [navView addSubview:backBtn];
    
    
    
    
    //title
    UILabel* lb_title = [[UILabel alloc]init];
    lb_title.textColor = [UIColor whiteColor];
    lb_title.font = [UIFont boldSystemFontOfSize:17 * WIDTHRADIU];
    lb_title.textAlignment = NSTextAlignmentCenter;
    [navView addSubview:lb_title];
    
    lb_title.text = self.title;
    
    [lb_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(navView);
        make.height.offset(25);
        make.top.offset(cl_kStatusBarHeight + 9.5);
    }];
    
    
//    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    [rightBtn setTitle:@"邀请有礼" forState:UIControlStateNormal];
//    [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    rightBtn.titleLabel.font = [UIFont systemFontOfSize:17];
//    [rightBtn addTarget:self action:@selector(rightBtnClick:) forControlEvents:UIControlEventTouchUpInside];
//    [navView addSubview:rightBtn];
//
//    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.equalTo(navView);
//        make.width.offset(80);
//        make.height.offset(44);
//        make.top.offset(cl_kStatusBarHeight);
//    }];
//
    
}



#pragma mark - 定时器处理
-(void) pauseTimer{
    
    
    
    if (self.isPause) {
        return;
    }
    
    self.isPause = YES;
    
    if(self.timer){
        dispatch_suspend(_timer);
    }
}
-(void) resumeTimer{
    
    
    
    if (self.isPause == NO) {
        return;
    }
    
    self.isPause = NO;
    
    if(self.timer){
        dispatch_resume(_timer);
    }
}
-(void) stopTimer{
    if(self.timer){
        dispatch_source_cancel(_timer);
        _timer = nil;
    }
}


#pragma mark - 通知绑定方法

///监听应用退到后台
 - (void)didEnterBackground
{
    if (!self.showTaskView) {
        return;
    }
   
    [self pauseTimer];
}
///恢复旋转
- (void)didBecomeActive
{
    if (!self.showTaskView) {
        return;
    }
    
    [self resumeTimer];
}




#pragma mark - 获取url
- (void)requestUrlFromServe
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCGetLittleGoldHouseUrlRequest];
    NSLog(@"获取小金库url:%@",url);
    
    NSString *province = [Tools isBlankString:[UserDefault objectForKey:@"locationProvince"]] ? @"" : [UserDefault objectForKey:@"locationProvince"];
    NSString *city = [Tools isBlankString:[UserDefault objectForKey:@"locationCity"]] ? @"" : [UserDefault objectForKey:@"locationCity"];
    NSString *county = [Tools isBlankString:[UserDefault objectForKey:@"locationCounty"]] ? @"" : [UserDefault objectForKey:@"locationCounty"];
    
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    
    
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"tel"];
    [params setObject:@([getPeopleID PeopleID]) forKey:@"uid"];
    [params setObject:province forKey:@"province"];
    [params setObject:city forKey:@"city"];
    [params setObject:county forKey:@"county"];
    
   
   
    NSLog(@"params:%@",params);
    WeakSelf
    [KKLoadingAnimationView show];
    [NetworkRequest Post6:url Params:params Success:^(id _Nonnull objc) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            NSString *result = objc[@"result"];
            if ([result isKindOfClass:[NSString class]]) {
                NSString *url = result;
                NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
                
                [weakSelf.webView loadRequest:request];
                
            }
           
        }else{
            [Tools showMessage:describe];
        }

    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        //[Tools showMessage:@"网络出小差了,请稍后重试"];
        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://lc.jr.jd.com/ck/xjkHold/index/?channel=a00308"]];
        [weakSelf.webView loadRequest:request];
    }];
}


#pragma mark - WKNavigationDelegate
//页面开始加载时调用
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation
{
    NSLog(@"WebVC:页面开始加载");
}
//当内容开始返回时调用
- (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation
{
    NSLog(@"WebVC:内容开始返回");
    
   
}
// 页面加载完成之后调用
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
{
    
    NSLog(@"WebVC:页面加载完成");

    if (!loadSuccess) {
        loadSuccess = YES;
//        [self startActivity];
        
        if (self.showTaskView) {
            [self addTaskView];
        }

        
    }
    

}

// 页面加载失败时调用
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error
{
    NSLog(@"WebVC:页面加载失败");
}
//接收到服务器跳转请求之后调用
- (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation
{
    NSLog(@"WebVC:接收到服务器跳转请求");
}

// 在收到响应后,决定是否跳转
- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(nonnull WKNavigationResponse *)navigationResponse decisionHandler:(nonnull void (^)(WKNavigationResponsePolicy))decisionHandler
{
    NSLog(@"WebVC:收到服务器响应,是否跳转");
    NSLog(@"%@",navigationResponse.response.URL.absoluteString);
    //允许跳转
    decisionHandler(WKNavigationResponsePolicyAllow);
    //不允许跳转
    //decisionHandler(WKNavigationResponsePolicyCancel);
}

static const NSString * CompanyFirstDomainByWeChatRegister = @"k.yaodouwang.com";
// 在发送请求之前,决定是否跳转
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
{
    NSLog(@"WebVC:发送请求之前,决定是否跳转");
    NSLog(@"%@",navigationAction.request.URL.absoluteString);
    
//    NSString* reqUrl = navigationAction.request.URL.absoluteString;
    NSString * scheme = [navigationAction.request.URL scheme];
    
    NSURL  * url = navigationAction.request.URL;
//    UIApplication *app = [UIApplication sharedApplication];
    //    appstore的外的包
        if ([url.absoluteString containsString:@"itms-appss://"] || [url.absoluteString containsString:@"downloadApp"]) {
//            [app openURL:url options:@{} completionHandler:^(BOOL success) {
//                
//            }];
            decisionHandler(WKNavigationActionPolicyCancel);
            return;
        }
    
    
    ///打电话
    if ([scheme isEqualToString:@"tel"]) {
        NSString *resourceSpecifier = [navigationAction.request.URL resourceSpecifier];
        NSString *callPhone = [NSString stringWithFormat:@"telprompt:%@", resourceSpecifier];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];
    }
    
    

    
     if (![scheme isEqualToString:@"https"] && ![scheme isEqualToString:@"http"]) {
           decisionHandler(WKNavigationActionPolicyCancel);
           
           if ([navigationAction.request.URL.absoluteString hasPrefix:@"weixin://"]) {
               [[UIApplication sharedApplication] openURL:navigationAction.request.URL];
           }
           return;
       }
       
    
    
    //允许跳转
    decisionHandler(WKNavigationActionPolicyAllow);
    //不允许跳转
    //decisionHandler(WKNavigationActionPolicyCancel);
}

#pragma mark - WKUIDelegate
//创建一个新的WebView
- (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures
{
    NSLog(@"WebVC:创建一个新的WebView");
     WKFrameInfo *frameInfo = navigationAction.targetFrame;
       if (![frameInfo isMainFrame]) {
           [webView loadRequest:navigationAction.request];
       }
       return nil;
}

//输入框
- (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(nullable NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString * _Nullable result))completionHandler
{
    NSLog(@"WebVC:输入框");
    completionHandler(@"http");
}
// 确认框
- (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL result))completionHandler{
    NSLog(@"WebVC:确认框");
    completionHandler(YES);
}
// 警告框
- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler{
    NSLog(@"WebVC:警告框");
    NSLog(@"%@",message);
    completionHandler();
}

#pragma mark - WKScriptMessageHandler
//被自定义的WKScriptMessageHandler在回调方法里通过代理回调回来，绕了一圈就是为了解决内存不释放的问题
//通过接收JS传出消息的name进行捕捉的回调方法
- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message{
    NSLog(@"name:%@\\\\n body:%@\\\\n frameInfo:%@\\\\n",message.name,message.body,message.frameInfo);
    if ([message.body isKindOfClass:[NSString class]]) {
//        NSString *type = message.body;
        
        
    }
    

}


//#pragma mark - 活动判断
//- (void)startActivity
//{
//    NSDate *oldTime = [[NSUserDefaults standardUserDefaults]objectForKey:@"KKGoldHouseActivityViewShowLastTime"];
//
//    BOOL hiddenActivity = oldTime && [self isSameDay:[NSDate date] date2:oldTime];
//    if (!hiddenActivity) {
//        WeakSelf
//        [KKGoldHouseActivityView showAlertViewWithVC:self block:^{
//
//            NSLog(@"领取方法");
//            //[weakSelf rightBtnClick:nil];
//            WebVC * vc = [WebVC new];
//            vc.title= @"存款有礼";
//            vc.url = @"http://nginx.weface.com.cn/appH5/kefuEarn/index.html";
//            vc.hidesBottomBarWhenPushed = YES;
//            [self.navigationController pushViewController:vc animated:YES];
//
//        }];
//
//        NSDate *oldDate = [NSDate date];
//        [[NSUserDefaults standardUserDefaults]setObject:oldDate forKey:@"KKGoldHouseActivityViewShowLastTime"];
//        [[NSUserDefaults standardUserDefaults]synchronize];
//    }
//}

#pragma mark - 进度视图
- (void)addTaskView
{
    UIView *taskView = [[UIView alloc]initWithFrame:CGRectMake(ScreenWidth - 77 * WIDTHRADIU, ScreenHeight - 300 * WIDTHRADIU, 57 * WIDTHRADIU, 55 * WIDTHRADIU)];
    [self.view addSubview:taskView];
    
    UIImageView *taskImage = [[UIImageView alloc]init];
    taskImage.frame = taskView.bounds;
    taskImage.image = [UIImage imageNamed:@"littleGoldHouseWindow"];
    [taskView addSubview:taskImage];
    
    
    UILabel *lb_content = [[UILabel alloc]init];
    lb_content.numberOfLines = 0;
    lb_content.textColor = [UIColor whiteColor];
    lb_content.textAlignment = NSTextAlignmentCenter;
    lb_content.font = [UIFont systemFontOfSize:8 * WIDTHRADIU];
    
    lb_content.text = @"浏览5秒\n领199金币";
    if (self.taskType == LittleGoldHouseTaskTypeCoins) {
        lb_content.text = @"浏览5秒\n领199金币";
    }else if (self.taskType == LittleGoldHouseTaskTypePackage) {
        lb_content.text = @"浏览5秒\n领取红包";
    }
    [taskView addSubview:lb_content];
    
    [lb_content mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.bottom.equalTo(taskView);
        make.left.offset(2 * WIDTHRADIU);
        make.height.offset(22 * WIDTHRADIU);
    }];
    
    self.lb_content = lb_content;
    
    
    UIButton *taskBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    taskBtn.frame = taskView.bounds;
    [taskBtn addTarget:self action:@selector(taskBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    taskBtn.userInteractionEnabled = NO;
    [taskView addSubview:taskBtn];
    
    self.taskBtn = taskBtn;
   
    [self startCount];
}

#pragma mark - 定时器活动
- (void)startCount
{
    
    if (self.timer == nil) {
        
        __block NSInteger time = 5; //倒计时时间
        dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
        dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
        

        dispatch_source_set_timer(timer,DISPATCH_TIME_NOW,1*NSEC_PER_SEC, 0); //每秒执行
        

        WeakSelf
        dispatch_source_set_event_handler(timer, ^{

            if(time <= 0){ //倒计时结束，关闭

                if (weakSelf.isDestoryTimer == NO) {
                    dispatch_source_cancel(timer);
                    weakSelf.isDestoryTimer = YES;
                }
                

                dispatch_async(dispatch_get_main_queue(), ^{
                    weakSelf.lb_content.text = @"任务完成\n返回领奖励";
                    weakSelf.taskBtn.userInteractionEnabled = YES;
                    if (weakSelf.block) {
                        weakSelf.block(YES);
                    }
                });

            }else{

                dispatch_async(dispatch_get_main_queue(), ^{
                    
                    if (weakSelf.taskType == LittleGoldHouseTaskTypeCoins) {
                        weakSelf.lb_content.text = [NSString stringWithFormat:@"浏览%ld秒\n领199金币",time];
                    }else if (weakSelf.taskType == LittleGoldHouseTaskTypePackage) {
                        weakSelf.lb_content.text = [NSString stringWithFormat:@"浏览%ld秒\n领取红包",time];
                    }
                   

                });
                NSLog(@"%ld",time);

                time--;
            }
        });

        dispatch_resume(timer);
        
        self.timer = timer;
        
    }
    
   
    
}


#pragma mark - event response
- (void)backClick:(UIButton *)sender {
    
    if (self.webView.canGoBack==YES) {
        [self.webView goBack];
    }else{
        if (self.fromHome) {
            [self.navigationController popViewControllerAnimated:YES];
        }else{
            [self.tabBarController.navigationController popViewControllerAnimated:YES];
        }
        
        
    }
    
    
}

//- (void)rightBtnClick:(UIButton *)sender
//{
//    WebVC * vc = [WebVC new];
//    vc.title= @"邀请有礼";
//    vc.url = @"http://nginx.weface.com.cn/appH5/work/activity/fund/share.html";
//    vc.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:vc animated:YES];
//}

- (void)taskBtnClick:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}


#pragma mark - 字典转json
/**
 *  字典转JSON字符串
 *
 *  @param dic 字典
 *
 *  @return JSON字符串
 */
- (NSString*) dictionaryToJson:(NSDictionary *)dic{
    NSString *json = nil;

    if ([NSJSONSerialization isValidJSONObject:dic]) {


      NSError *error;

      NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:0 error:&error];

      if(!error) {

          json =[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

      }

      else {

          NSLog(@"JSON parse error: %@", error);

      }
    }

    else {

      NSLog(@"Not a valid JSON object: %@", dic);
    }

    return json;
}

#pragma mark - 去除空白换行

-(NSString *)noWhiteSpaceString:(NSString *)newString {
 //去除掉首尾的空白字符和换行字符
   newString = [newString stringByReplacingOccurrencesOfString:@"\r" withString:@""];
   newString = [newString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
   newString = [newString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];  //去除掉首尾的空白字符和换行字符使用
   newString = [newString stringByReplacingOccurrencesOfString:@" " withString:@""];
//    可以去掉空格，注意此时生成的strUrl是autorelease属性的，所以不必对strUrl进行release操作！
   return newString;
}

#pragma mark - 判断是否同一天
- (BOOL)isSameDay:(NSDate*)date1 date2:(NSDate*)date2
{
    NSCalendar* calendar = [NSCalendar currentCalendar];
    unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
    NSDateComponents* comp1 = [calendar components:unitFlags fromDate:date1];
    NSDateComponents* comp2 = [calendar components:unitFlags fromDate:date2];
    return [comp1 day] == [comp2 day] &&
    [comp1 month] == [comp2 month] &&
    [comp1 year] == [comp2 year];
}



#pragma mark - getters and setters

- (void)setFromHome:(BOOL)fromHome
{
    _fromHome = fromHome;
    
    if (fromHome) {
        [self.webView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.offset(cl_kNavigationBarHeight);
            make.left.right.offset(0);
            make.bottom.offset(0);
        }];
    }
}



- (WKWebView *)webView
{
    if (!_webView) {
        //创建网页配置对象
        WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
        
        config.preferences.javaScriptEnabled = YES;
        config.preferences.javaScriptCanOpenWindowsAutomatically = YES;
        config.allowsInlineMediaPlayback = YES;
        config.allowsPictureInPictureMediaPlayback = YES;
        
        //自定义的WKScriptMessageHandler 是为了解决内存不释放的问题
        WeakWebViewScriptMessageDelegate *weakScriptMessageDelegate = [[WeakWebViewScriptMessageDelegate alloc]initWithDelegate:self];
        
        //这个类主要用来做native与JavaScript的交互管理
        WKUserContentController * wkUController = [[WKUserContentController alloc] init];
        
        //注册一个name为jsToOcNoPrams的js方法 设置处理接收JS方法的对象
        [wkUController addScriptMessageHandler:weakScriptMessageDelegate  name:@"kkshHelper"];
       
      
        
       config.userContentController = wkUController;
        

      
        _webView = [[WKWebView alloc]initWithFrame:CGRectMake(0, cl_kNavigationBarHeight, ScreenWidth, (ScreenHeight - cl_kNavigationBarHeight - cl_kTabBarHeight)) configuration:config];
        _webView.UIDelegate = self;
        _webView.navigationDelegate = self;
        
        _webView.scrollView.bounces = false;
        
    }
    return _webView;
}

/*
#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
