我的需求是为iPad创建phonegap组件。
我使用的是XCode 4.2和Phonegap1.9.0SDK。
我有一组需要用于iOS的原生phonegap类文件。我为iOS原生代码创建了插件类。我的代码还包含javascript代码。我需要通过javascript代码调用iOS代码。
我的iOS代码包含数组形式的参数。我们可以将数组迭代为objectAtIndex 1,2等。如何使用下面的参数从编写的插件类调用本机代码
插件代码:
- (void) myMethod:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
NSString* callbackId = [arguments objectAtIndex:0];
CDVPluginResult* pluginResult = nil;
NSString* javaScript = nil;
@try {
NSString* myarg = [arguments objectAtIndex:1];
if (myarg != nil) {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
javaScript = [pluginResult toSuccessCallbackString:callbackId];
}
} @catch (id exception) {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_JSON_EXCEPTION messageAsString:[exception reason]];
javaScript = [pluginResult toErrorCallbackString:callbackId];
}
[self writeJavascript:javaScript];
}本机代码:
-(NSArray*)nativeFunctionDisplay:(NSArray*)args;我需要在插件类中调用这个本机代码
参数值取自javascript函数。在js文件中,我需要调用plugin类并传递参数。
Javascript.js:
var arg1;
var arg2;
var arg 3;
PluginClass.callNativeFunction(<How to pass the arguments here>)我看到了许多示例,但它们都是为了获得初始内容而尝试的,例如成功时的警告消息。
你能帮帮忙吗。
发布于 2013-02-14 03:06:45
var arg1;
var arg2;
var arg3;
PluginClass.callNativeFunction([arg1, arg2, arg3]);你只需要在Javascript中创建一个数组。
Rohde Fischer为iOS写了一些很好的例子
https://github.com/rohdef/PGPlugins/blob/3_Arguments/www/pluginExample.js
https://stackoverflow.com/questions/14860855
复制相似问题