iOS和html交互:oc调用html方法

比如在手机上点击一个oc按钮要展示后台数据,而html已经做了和后台交互,oc可以直接通知html返回数据

html端:定义方法

  • 无参数

      function getData() {}

  • 一个参数

      function getDataWithId(id){}

  • 多个参数

      function getDataWithMsg(id, date){}

oc端:

  • 用UIWebView展示html页面
  • 等页面加载完成,在webViewDidFinishLoad方法里调用js方法

      [webView stringByEvaluatingJavaScriptFromString:@"getData()"];//无参数

      [webView stringByEvaluatingJavaScriptFromString:@"getDataWithId('79882')"];//一个参数

      [webView stringByEvaluatingJavaScriptFromString:@"getDataWithMsg('79882', '20190116')"];//多个参数

猜你喜欢

转载自blog.csdn.net/weixin_42012181/article/details/86504311