zoukankan      html  css  js  c++  java
  • iOS7 中的JavaScriptCore简单介绍

    以前写过一篇介绍如何使用第三方库在ios上进行js和oc交互调用的文章,链接如下 iOS 使用UIWebView把oc代码和javascript相关联。当时建立项目时,仍然是ios6时代,所以没有原生的交互方法。但是在ios7中,我们有了JavaScriptCore!

    JavaScriptCore的基本目的和以前的第三方库的基本目的一致,就是为了实现js和oc之间的相互调用。但是JavaScriptCore更为好用。首先调用js在也不依赖于uiwebview了。其次oc和js的交互逻辑变得简单了,以前你需要如下做:

    This may sound like old news to you if you've already integrated native apps with web apps. Couldn't you do all of that before using a UIWebView?
    You're absolutely right; in previous versions of iOS, you could pass a JavaScript string to your web view with the stringByEvaluatingJavaScriptFromString: message.
    And if you wanted to run Objective-C from JavaScript, you could open a URL with a custom scheme (e.g. foo://) and handle it in the web view's delegate method webView:shouldStartLoadWithRequest:navigtionType.
    

     这样做的后果就是你的代码逻辑会比价复杂,因为你需要自己实现一些JavaScriptCore中自动实现的功能。

    关于JavaScriptCore的详细使用,请参看 iOS 7 by Tutorials。

  • 相关阅读:
    如何处理数集据不平衡的问题
    xgb&lgb&ctb区别
    LDA与gibbs采样
    撸了一个 Feign 增强包
    行为驱动模型-Behave
    MySQL 主从复制常见错误答疑
    POJ 1191
    POJ 1141
    HDU 1754
    POJ 3468
  • 原文地址:https://www.cnblogs.com/breezemist/p/3723054.html
Copyright © 2011-2022 走看看