zoukankan      html  css  js  c++  java
  • Webview获取H5页面js方法参数

    
    

     #import<JavaScriptCore/JavaScriptCore.h>

    
    
    #pragma mark UIWebViewDelegate
    
    - (void)webViewDidFinishLoad:(UIWebView *)webView
    {
        [SVProgressHUD dismissWithDelay:0.1];
        JSContext *jsContext = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
        
        jsContext[@"openLink"] =^(id obj,id obj1){
            
            NSInteger attacmentId = 0;
            NSString *attacmentType = nil;
            
            NSRange range = [obj rangeOfString:@"link_"];
            attacmentId = [[obj substringFromIndex:range.length] integerValue];
            
            NSRange rangeType =  [obj1 rangeOfString:@"." options:NSBackwardsSearch];
            attacmentType = [obj1 substringFromIndex:rangeType.location];
            
            InvestInnovationAttacmentViewController *vc = [[InvestInnovationAttacmentViewController alloc]init];
            
            NSString *strUrl = [[MSCoreManager sharedManager]getAttachmetURL:@(attacmentId)];
            vc.urlLink = strUrl;
            vc.type = attacmentType;
            [self.navigationController pushViewController:vc animated:YES];
    
        
        };
        
        jsContext.exceptionHandler = ^(JSContext *context, JSValue *exceptionValue) {
            context.exception = exceptionValue;
            //比如把js中的方法名改掉,OC找不到相应方法,这里就会打印异常信息
            MSLog(@"异常信息:%@", exceptionValue);
        };
        
    }//
  • 相关阅读:
    poj 3669 Meteor Shower
    poj 3009 Curling 2.0
    poj 1979 Red and Black
    区间内素数的筛选
    九度oj 题目1347:孤岛连通工程
    poj 3723 Conscription
    poj 3255 Roadblocks
    Luogu P3975 [TJOI2015]弦论
    AT2165 Median Pyramid Hard 二分答案 脑洞题
    后缀自动机多图详解(代码实现)
  • 原文地址:https://www.cnblogs.com/zhujin/p/6168709.html
Copyright © 2011-2022 走看看