简体   繁体   English

从本地iOS调用Java脚本函数

[英]calling java script function from native iOS

I am looking for the possibility of calling the Java Script function from native iOS. 我正在寻找从本地iOS调用Java Script函数的可能性。

Generally we prefer the below method which could be used to call JS function from iOS. 通常,我们更喜欢以下可用于从iOS调用JS函数的方法。

NSString *returnvalue = [webView stringByEvaluatingJavaScriptFromString:@"your javascript code string here"];

But, in my case I need to call the function name as jsObject.FunctionName() like this. 但是,就我而言,我需要像这样将函数名称称为jsObject.FunctionName()。

NSString *returnvalue = [webView stringByEvaluatingJavaScriptFromString:@"jsObject.FunctionName()"];

Any idea, could be appreciated. 任何想法,不胜感激。

EDITED: 编辑:

IDEA : What we are trying to do is, instead of calling first method and keeping global variable for the reference in Java Script side, We can call the function wrt to each object. 想法:我们想要做的是,可以调用每个对象的函数wrt,而不是调用第一个方法并在Java Script端保留引用的全局变量。

Java script code calling through iOS 通过iOS调用的Java脚本代码

  1. Through Javascript core Engine. 通过Javascript核心引擎。
  2. Through Web view 通过网络视图

In first technique, 在第一种技术中

You will create a JSContext against .JS file then you will use keyedScript for method calling and then call function will trigger that JS method. 您将针对.JS文件创建JSContext,然后将keyedScript用于方法调用,然后调用函数将触发该JS方法。

Follow Raywenderlich for detailed help. 请关注Raywenderlich以获取详细帮助。 https://www.raywenderlich.com/1227-javascriptcore-tutorial-for-ios-getting-started https://www.raywenderlich.com/1227-javascriptcore-tutorial-for-ios-getting-started

No Experience of second Web View JS technique. 没有第二种Web View JS技术的经验。

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

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