首先h5方法要求
? 如圖:
button 后面的onclick="commitss()" , 點(diǎn)擊方法名commitss()是兩邊商量好固定不變的
在app端:
? - (void)webViewDidFinishLoad:(UIWebView *)webView
{
JSContext* jsContext = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
//捕獲異常信息
jsContext.exceptionHandler = ^(JSContext *context, JSValue *exceptionValue)
{? ? context.exception = exceptionValue;
NSLog(@"異常信息:%@", exceptionValue);
};
jsContext[@"commitss"] = ^(NSString *str)
{
NSLog(@"_________%@",str);
};
}
注:// str 為點(diǎn)擊網(wǎng)頁上的button傳遞的參數(shù)
參數(shù)的格式要button傳遞的參數(shù)類型一致才可取到對應(yīng)的參數(shù)信息。