// // KXbodyPriceColumnViewController.m // CAISHEN // // Created by jikaipeng on 2017/8/25. // Copyright © 2017年 kuxuan. All rights reserved. // #import "KXbodyPriceColumnViewController.h" #import #import "KXBodyPriceJS.h" #import "KXWebDetailViewController.h" #import "KXMainDetailViewController.h" @interface KXbodyPriceColumnViewController () { UIWebView *_webView; } @property (nonatomic,strong)JSContext *context; @end @implementation KXbodyPriceColumnViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.name = self.titleString; [self createNavigation]; [self loadingWebView]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(push:) name:@"WTWEBDETAILJSOBJC" object:nil]; } - (void)push:(NSNotification *)noti { NSDictionary *userinfo = noti.object; NSDictionary *dict = userinfo[@"product"]; if ([dict[@"type"] isEqual:@"1"]) { KXWebDetailViewController *web=[[KXWebDetailViewController alloc]init]; web.webStr=dict[@"link"]; web.product_id = dict[@"product_Id"]; web.product_apply_id = @"0"; [self.navigationController pushViewController:web animated:YES]; }else{ KXMainDetailViewController *detail=[[KXMainDetailViewController alloc]init]; detail.detailID=dict[@"product_Id"]; detail.enterSource = self.enterSource; [self.navigationController pushViewController:detail animated:YES]; } } -(void)createNavigation { [self addLeftBarButtonItemWithImageName:@"main_back" title:nil target:self selector:@selector(backAction)]; } -(void)backAction { [self.navigationController popViewControllerAnimated:YES]; } -(void)loadingWebView { _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-NavHeight-safeBottomHeight)]; _webView.delegate=self; _webView.scalesPageToFit=YES; [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.webString]]]; [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(@"开始加载"); NSDate *date = [[NSUserDefaults standardUserDefaults]objectForKey:KXMARK_TODAY]; if (!date) { [[NSNotificationCenter defaultCenter]postNotificationName:@"mark" object:nil]; } //[self.hud showAnimated:YES]; } - (void)webViewDidFinishLoad:(UIWebView *)webView { if (webView.isLoading) { return; } //[self.hud hideAnimated:YES]; NSLog(@"结束加载"); self.context = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"]; self.context.exceptionHandler = ^(JSContext *context, JSValue *exceptionValue) { context.exception = exceptionValue; }; //__weak typeof (self)temp = self; KXBodyPriceJS *body = [[KXBodyPriceJS alloc]init]; self.context[@"native"] = body; } - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { //[self.hud hideAnimated:YES]; NSLog(@"加载失败"); } - (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