Keine Beschreibung

KXbodyPriceColumnViewController.m 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //
  2. // KXbodyPriceColumnViewController.m
  3. // CAISHEN
  4. //
  5. // Created by jikaipeng on 2017/8/25.
  6. // Copyright © 2017年 kuxuan. All rights reserved.
  7. //
  8. #import "KXbodyPriceColumnViewController.h"
  9. #import <JavaScriptCore/JavaScriptCore.h>
  10. #import "KXBodyPriceJS.h"
  11. #import "KXWebDetailViewController.h"
  12. #import "KXMainDetailViewController.h"
  13. @interface KXbodyPriceColumnViewController ()<UIWebViewDelegate>
  14. {
  15. UIWebView *_webView;
  16. }
  17. @property (nonatomic,strong)JSContext *context;
  18. @end
  19. @implementation KXbodyPriceColumnViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. // Do any additional setup after loading the view.
  23. self.name = self.titleString;
  24. [self createNavigation];
  25. [self loadingWebView];
  26. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(push:) name:@"WTWEBDETAILJSOBJC" object:nil];
  27. }
  28. - (void)push:(NSNotification *)noti
  29. {
  30. NSDictionary *userinfo = noti.object;
  31. NSDictionary *dict = userinfo[@"product"];
  32. if ([dict[@"type"] isEqual:@"1"]) {
  33. KXWebDetailViewController *web=[[KXWebDetailViewController alloc]init];
  34. web.webStr=dict[@"link"];
  35. web.product_id = dict[@"product_Id"];
  36. web.product_apply_id = @"0";
  37. [self.navigationController pushViewController:web animated:YES];
  38. }else{
  39. KXMainDetailViewController *detail=[[KXMainDetailViewController alloc]init];
  40. detail.detailID=dict[@"product_Id"];
  41. detail.enterSource = self.enterSource;
  42. [self.navigationController pushViewController:detail animated:YES];
  43. }
  44. }
  45. -(void)createNavigation
  46. {
  47. [self addLeftBarButtonItemWithImageName:@"main_back" title:nil target:self selector:@selector(backAction)];
  48. }
  49. -(void)backAction
  50. {
  51. [self.navigationController popViewControllerAnimated:YES];
  52. }
  53. -(void)loadingWebView
  54. {
  55. _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-NavHeight-safeBottomHeight)];
  56. _webView.delegate=self;
  57. _webView.scalesPageToFit=YES;
  58. [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.webString]]];
  59. [self.view addSubview:_webView];
  60. }
  61. #pragma UIWebViewDelegate
  62. - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
  63. navigationType:(UIWebViewNavigationType)navigationType
  64. {
  65. if (navigationType==UIWebViewNavigationTypeBackForward) {
  66. _webView.canGoBack?[_webView goBack]:[self.navigationController popViewControllerAnimated:YES];
  67. }
  68. return YES;
  69. }
  70. - (void)webViewDidStartLoad:(UIWebView *)webView
  71. {
  72. NSLog(@"开始加载");
  73. NSDate *date = [[NSUserDefaults standardUserDefaults]objectForKey:KXMARK_TODAY];
  74. if (!date) {
  75. [[NSNotificationCenter defaultCenter]postNotificationName:@"mark" object:nil];
  76. }
  77. //[self.hud showAnimated:YES];
  78. }
  79. - (void)webViewDidFinishLoad:(UIWebView *)webView
  80. {
  81. if (webView.isLoading) {
  82. return;
  83. }
  84. //[self.hud hideAnimated:YES];
  85. NSLog(@"结束加载");
  86. self.context = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
  87. self.context.exceptionHandler = ^(JSContext *context, JSValue *exceptionValue)
  88. {
  89. context.exception = exceptionValue;
  90. };
  91. //__weak typeof (self)temp = self;
  92. KXBodyPriceJS *body = [[KXBodyPriceJS alloc]init];
  93. self.context[@"native"] = body;
  94. }
  95. - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
  96. {
  97. //[self.hud hideAnimated:YES];
  98. NSLog(@"加载失败");
  99. }
  100. - (void)didReceiveMemoryWarning {
  101. [super didReceiveMemoryWarning];
  102. // Dispose of any resources that can be recreated.
  103. }
  104. /*
  105. #pragma mark - Navigation
  106. // In a storyboard-based application, you will often want to do a little preparation before navigation
  107. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  108. // Get the new view controller using [segue destinationViewController].
  109. // Pass the selected object to the new view controller.
  110. }
  111. */
  112. @end