简体   繁体   English

从JavaScript调用Objective-C方法

[英]Calling Objective-C methods from JavaScript

From documentation , it seems to be possible except for the sentence highlighted : 文档中看,除了突出显示的句子外,似乎还有可能:

The web scripting capabilities of WebKit permit you to access Objective-C properties and call Objective-C methods from the JavaScript scripting environment. WebKit的Web脚本功能允许您访问Objective-C属性并从JavaScript脚本环境中调用Objective-C方法。

An important but not necessarily obvious fact about this bridge is that it does not allow any JavaScript script to access Objective-C . 关于此桥的重要但不一定明显的事实是, 它不允许任何JavaScript脚本访问Objective-C You cannot access Objective-C properties and methods from a web browser unless a custom plug-in has been installed. 除非已安装自定义插件,否则您无法从Web浏览器访问Objective-C属性和方法。 The bridge is intended for people using custom plug-ins and JavaScript environments enclosed within WebKit objects (for example, a WebView). 该桥适用于使用自定义插件和WebKit对象(例如WebView)中包含的JavaScript环境的人们。

Or should I consider the solution from Sixten Otto shown here ? 还是应该考虑此处显示的Sixten Otto的解决方案? What I wish to do is : when user tap on an image in UIWebView a JavaScript routine calls a method in Objective-C. 我想做的是:当用户点击UIWebView中的图像时,JavaScript例程将调用Objective-C中的方法。

Did you see this JavaScriptFromObjC 您看到这个JavaScriptFromObjC

and this question 这个问题

Take a look at open source project Apache Cordova . 看一下开源项目Apache Cordova You'll learn how to interact with native code for other mobile platforms, too. 您还将学习如何与其他移动平台的本机代码交互。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM