简体   繁体   中英

Create own plugin in phonegap for windows phone

I want to pass string value from c# to JavaScript using JSON. So I created an example plugin name: Echo.cs (in CordovaWP namespace), and an "echo" method in Echo class. Like this tutorial .

In index.js, I called:

 cordova.exec(function (result) 
        {
            alert("OK");
        }, function (error) {
            alert("KO");
        }, "CordovaWP.Echo", "echo", "ok");

But I can't get debug in echo method. And have nothing found!

Use as below:

cordova.exec(function (result) 
    {
        alert("OK");
    }, function (error) {
        alert("KO");
    }, "CordovaWP.Echo", "echo", ["ok"]);

Parameters should always be sent as an array from JS to cs

Please can you also post your CS code:

Check sample below SMS example:

JS:

    var sendSMS = function(phoneNumber,smsBody){
    cordova.exec(function(){console.log("success SMS");},function(){console.log("Error SMS");},"SMS", "sendSMS", [phoneNumber,smsBody]);
};

CS:

 namespace Cordova.Extension.Commands{
   public class SMS : BaseCommand
    { 
        public void sendSMS(string arg)
        {
            string recipient = JsonHelper.Deserialize<string[]>(arg)[0];
            string smsBody = JsonHelper.Deserialize<string[]>(arg)[1];
            SmsComposeTask composeSMS = new SmsComposeTask();
            composeSMS.Body = smsBody;
            composeSMS.To = recipient;
            composeSMS.Show();
            this.DispatchCommandResult();
        }

    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM