Try using the new format for PhoneGap.exec which is documented in
PhoneGapLib\javascripts\core\phonegap.base.js.
PhoneGap.exec(successCallback, errorCallback, class, method, [arg1,
arg2, {"myArray": arrayObj, "myOtherObj": otherObj}]);
successCallback and errorCallback can be null if there is no
callback. Pass the arguments in an array. An object within the array
will be passed within the options dictionary. The other arguments
will be in the arguments array. Arrays should be passed as part of an
object and then be retrieved via the options dictionary.
Here is an example for contacts.find() in contacts.js:
PhoneGap.exec(successCB, errorCB, "com.phonegap.contacts","search",
[{"fields":fields, "findOptions":options}]);
Note that fields is an array object and is passed as an object and
will be retrieved on the iOS side via from the options dictionary.
-becky
On Jul 26, 11:59 am, Khanh Nguyen <
chepukhas...@gmail.com> wrote:
> I'm writing a phonegap plugin for iOS.
> I need to pass array to my function in javascript file. However, in .m file,
> these arrays are not seen and understood.
> Following is the details of the problem. In test.js, I call test() function
> with 2 arrays and 1 string.
> In MyPlugin.m, in test() function, however, the number of arguments shown is
> only 1.
>
> So, my question is how can I do to pass arrays to my function?
>
> ----------- *plugin.js* --------------------
> function MyPlugin(){
>
> };
>
> MyPlugin.prototype.*test* = function(arg1, arg2, arg3){
> *PhoneGap.exec*('MyPlugin.test', arg1, arg2, arg3);
>
> }
>
> .....
> ------------------------------------------
>
> ---------------declare plugin----------------
> function onDeviceReady() {
> *myPlugin* = window.plugins.plugin;}
>
> --------------------------------------------------
>
> -----------test.js where function is called----------------
> function testPlugin(){
> var arr1 = new Array(),
> arr2 = newArray(),
> text = 'sample string';
> *myPlugin.test(arr1, arr2, text);*};
>
> -----------------------------------------------------------------------
>
> --------------MyPlugin.m--------------------------
> -(void)test:(NSMutableArray*)arguments
> withDict:(NSMutableDictionary*)options
> {
> NSUInteger argc = [arguments count];
> NSLog(@"Number of arguments: %d", argc); //output: *Number of
> arguments: 1*
>
> NSString *text = [arguments objectAtIndex:0];
> NSLog(@"%@", text); //output:* sample string*}
>
> ---------------------------------------------------------
>
> Thanks,
> --
> *Khanh Nguyen*