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);
}

這樣子簡單的發送短信的功能就實現了,但是本人發現它不能夠滿足羣發短信的需求,所以如果想做羣發消息的功能就得另尋他法了!


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章