通信的JavaScript和Objective-C之间(IOS) [英] Communication between javascript and Objective-c (IOS)

查看:149
本文介绍了通信的JavaScript和Objective-C之间(IOS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道的iOS和JavaScript之间的通信的方法是在JS创建假冒的URL并追加将被用来作为参数传递给Objective-C的code串并分析在此委托方法网址:

I know the way to communicate between iOS and javascript is to create fake URLs in JS and append a string which will be used as parameter to the Objective-C code and parse that URL in this delegate method:

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType

然后通过调用本地方法发送的返回值 stringByEvaluatingJavaScriptFromString 与参数CALLID一次。

Then send the return value by calling the native method stringByEvaluatingJavaScriptFromString again with parameter callID.

但我想,就像机器人,直接调用JS从Objective-C的方法,并得到一个返回值。而不是需要来使用JavaScript编写的任何方法来获取返回值。其实我们有JS code了。它完美的作品,同时与Android通信。

But I want to, just like Android, directly call Objective-C methods from JS and get a return value. Instead of needing to write any method in JavaSCript to get the return value. Actually we have JS code already. It works perfectly while communicating with Android.

有没有什么技巧来解决我的问题,这将在AppStore上?

Are there any tricks to solve my problem that will be approved on the AppStore?

推荐答案

您可以通过简单的步骤从调用Objective C的JavaScript方法。

You can call javascript methods from objective C using simple steps.

请通过
又见<一个href=\"https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/DisplayWebContent/Tasks/JavaScriptFromObjC.html\"相对=nofollow>苹果文档

这篇关于通信的JavaScript和Objective-C之间(IOS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆