1

Working on some testing with phonegap on iphone; i have a plugin that returns simpl json data like this :

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); }

Doesn't produce anything upon the return.

Any idea ?

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
Disco
  • 4,226
  • 11
  • 58
  • 76

2 Answers2

1
// 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 ]; 
Aaron Saunders
  • 33,180
  • 5
  • 60
  • 80
  • Thanks, now I get a 'arguments' not declared (really dumb question i admit, but never done a single line of C code) – Disco Nov 23 '10 at 17:57
0

As a reply 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 plugin method should have a parameter called arguments, which is 'filled' by the calling cordova.exec function.

saltandpepper
  • 998
  • 2
  • 12
  • 32