How to implement a telephone callback

Work on some testing with telephone communication on iphone; I have a plugin that returns simple json data as follows:

NSString* retStr = [[NSString alloc] 
  initWithFormat:@"%@({ code: '%@', image: '%@' });", 
  resultText.text,resultImage.image];                       

[ webView stringByEvaluatingJavaScriptFromString:retStr ];  

And my call from JS:

var mydata = PhoneGap.exec("MyModile.myFunction", 'mycallback'); 

function mycallback (data) { alert (data); }

Does not return anything on return.

Any idea?

+1
source share
2 answers
// get the callback from the arguments
NSString * jsCallback = [arguments objectAtIndex:0];

// create the string
NSString* retStr = [[NSString alloc] 
    initWithFormat:@"%@({ code: '%@', image: '%@' });", 
                                jsCallback,resultText.text,resultImage.image];  

//execute
[ webView stringByEvaluatingJavaScriptFromString:retStr ]; 
+1
source

In response to your comment on Aaron Saunders:

Take a look at this wiki: http://wiki.phonegap.com/w/page/36753496/How%20to%20Create%20a%20PhoneGap%20Plugin%20for%20iOS

Your native plug-in module should have a parameter called arguments, which is "populated" with the calling function cordova.exec.

0
source

All Articles