Reputation: 1680
I am creating phoneGap plugin for iOS, which draws signature using NativeCode and Pass call back value to JavaScript.
I'm able to draw the signature succesfully using natice code but I'm not able to do pass return value of saved signature, to JavaScript.
JavaScript code is as follow
var MyPlugin = {
nativeFunction: function(types, success, fail) {
return Cordova.exec(success, fail, "MyPlugin", "print", types);
}
};
In "print" function I am calling a UIViewContoller class which draws signature, and on SAVE button I want to pass return value to JavaScript.
Code on SAVE button click
// 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]];
}
I am not getting any error or any exception.
Can anyone please help me out. Any suggetion will be appreciated.
Thanks in Advance.
Upvotes: 3
Views: 2562
Reputation: 16060
Take a look at this GitHub project: https://github.com/rohdef/PGPlugins
There are some good examples of writing plugins for phonegap.
Upvotes: 2