1、需求描述
最近做的项目需要有提醒用户的功能,就是可以调用手机的发送短信功能
2、准备
①、添加插件$cordovaSMS
cordova plugin add https://github.com/cordova-sms/cordova-sms-plugin.git
②、在controller中添加依赖
3、代码实现
//发短信
$scope.sendMessage=function(){
//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
}
};
$cordovaSms
.send('18654332789', 'SMS content',options)
.then(function() {
// Success! SMS was sent
CommonJs.AlertPopup("发送短信成功");
}, function(error) {
// An error occurred
});
};
4、注意点
看来很多东西都需要去官网看原代码和文档,ng-cordova的文档也不全,没有介绍option怎么配置,可以从github上找一些开源的其他插件。怎么找其他的开源插件介绍一下
https://github.com/cordova-sms/cordova-sms-plugin 官网地址和介绍。