Cordova各個插件使用介紹系列(一)—$cordovaSms發送短信

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

 

這是調用手機發送短信的插件,由於在作項目的時候有這個需求找了一下看到這個,在這裏簡單介紹一下,使用以前有必定的ionic基礎和開發項目的經驗。git

一、首先須要有一個簡單的項目,而後在命令行輸入添加插件的命令:github

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

二、在HTML中的代碼以下:app

 

<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" />

 

三、在JS中的代碼以下,這個代碼寫在相應的控制器裏而且依賴‘$cordovaSms’,記得在app.js裏依賴‘ngCordova’,:ionic

 

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


這樣子簡單的發送短信的功能就實現了,可是本人發現它不可以知足羣發短信的需求,因此若是想作羣發消息的功能就得另尋他法了!spa

相關文章
相關標籤/搜索