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);
    };
    
}//

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM