I am using the following code,
var iphoneUrl = 'myScheme://{0}?{1}'
function callNativeFunction(functionName) {
var args = Array.prototype.slice.call(arguments, 1);
if (window.andriod) {
andriod[functionName].apply(this, args);
}
else {
var params = '';
for (var i = 0, len = args.length; i < len; i++) {
params += 'param' + (i + 1) + '=' + encodeURIComponent(args[i]) + '&';
}
params = params.slice(0, -1);// remove last &
window.location = iphoneUrl.format(functionName, params);
}
}
callNativeFunction('functionName', 'param1');
Here is String.Format,
String.prototype.format = function () {
var args = arguments;
return this.replace(/{(\d+)}/g, function (match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
});
};
which great but on andriod webview apply is not working. alert(andriod[functionName])
give me 'function myFunc(..){[native Code]}'
. But andriod[functionName]
does not call the function. Not If use andriod.myFunc
then it works but I don't want the function to be hard coded.