Cordova各个插件使用介绍系列(一)—$cordovaSms发送短信

详情链接地址:http://www.ncloud.hk/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/cordova-1-cordovasms/

 

这是调用手机发送短信的插件,因为在做项目的时候有这个需求找了一下看到这个,在这里简单介绍一下,使用之前有一定的ionic基础和开发项目的经验。

1、首先需要有一个简单的项目,然后在命令行输入添加插件的命令:

cordova plugin add https://github.com/cordova-sms/cordova-sms-plugin.git

2、在HTML中的代码如下:

 

<input id="numberTxt" placeholder="Enter mobile number" value="" type="tel" />
<textarea id="messageTxt" placeholder="Enter message"></textarea>
<input type="button" ng-click="sendSms()" value="Send SMS" />

 

3、在JS中的代码如下,这个代码写在相应的控制器里并且依赖‘$cordovaSms’,记得在app.js里依赖‘ngCordova’,:

 

$scope.sendSms = function () {
    var number = document.getElementById('numberTxt').value;
    var message = document.getElementById('messageTxt').value;
    alert(number);
    alert(message);

    //CONFIGURATION
    var options = {
        replaceLineBreaks: false, // true to replace \n by a new line, false by default
        android: {
            intent: 'INTENT'  // send SMS with the native android SMS messaging
            //intent: '' // send SMS without open any other app
        }
    };

    var success = function () {
        alert('Message sent successfully');
    };
    var error = function (e) {
        alert('Message Failed:' + e);
    };
    sms.send(number, message, options, success, error);
}


这样子简单的发送短信的功能就实现了,但是本人发现它不能够满足群发短信的需求,所以如果想做群发消息的功能就得另寻他法了!

 

posted @ 2016-02-19 11:38  jun_zx  阅读(1710)  评论(0编辑  收藏  举报