我正在为 iOS 创建 phoneGap 插件,它使用 NativeCode 绘制签名并将回调值传递给 JavaScript。
我可以使用 natice 代码成功绘制签名,但我无法将保存的签名的返回值传递给 JavaScript。
JavaScript 代码如下
var MyPlugin = {
nativeFunction: function(types, success, fail) {
return Cordova.exec(success, fail, "MyPlugin", "print", types);
}
};
在“打印”函数中,我调用了一个绘制签名的 UIViewContoller 类,在“保存”按钮上,我想将返回值传递给 JavaScript。
保存按钮上的代码单击
// The first argument in the arguments parameter is the callbackID.
// We use this to send data back to the successCallback or failureCallback
// through PluginResult
self.callbackID = [arguments pop];
// Get the string that javascript sent us
NSString *stringObtainedFromJavascript = [arguments objectAtIndex:0];
// Create the Message that we wish to send to javascript
NSMutableString *stringToReturn = [NSMutableString stringWithString: @"StringReceived:"];
// Append the received string to the string we plan to send out
[stringToReturn appendString: stringObtainedFromJavascript];
// Create Plugin Result
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsString: [stringToReturn stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
// Checking if the string received is HelloWorld or not
if ([stringObtainedFromJavascript isEqualToString:@"SAVED"] == YES)
{
// Call the javascript success function
[self writeJavascript: [pluginResult toSuccessCallbackString:self.callbackID]];
}else
{
// Call the javascript error function
[self writeJavascript: [pluginResult toErrorCallbackString:self.callbackID]];
}
我没有收到任何错误或任何异常。
谁能帮帮我。任何建议将不胜感激。
提前致谢。