I’m writing a phonegap plugin for iOS.
In javascript file, I need to pass some arrays to my function. However, in the .m file, [arguments count] only shows me the number of ‘string’ arguments that I passed to my function. That means, the arrays passed to my function are not understood/seen in the .m file.
Following is the senario:
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.
----------- plugin.js --------------------
function MyPlugin(){
};
MyPlugin.prototype.test = function(arg1, arg2, arg3){
PhoneGap.exec('MyPlugin.test', arg1, arg2, arg3);
}
//.....code is omitted......
------------------------------------------
---------------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
}
---------------------------------------------------------
So my question is how can I pass arrays to javascript function in phonegap plugin for iOS.
Thanks
My solution for this problem is that I stringify the arrays, and pass them to the function as string. Then in .m file, I parse these strings into arrays.
That solves the problem. But if you know of any other solutions, please do recommend.
THanks,