我正在使用Ionic开发一个Android应用程序,我想在我的应用程序中实现SMS功能。我已经安装了cordova-sms-plugin并将以下代码添加到我的应用程序中。
.controller('requestCtrl', function($scope,AuthService,RequestService,$cordovaSms) {
$scope.sendsms = function(){
document.addEventListener("deviceready",function(){
var options = {
replaceLineBreaks: false,
android:{
//intent : 'INTENT',
intent : ''
}
};
$cordovaSms.send('9487354083','This is a test sms', options).then(function(){
alert("success! sms was sent");
},function(error){
console.log(error);
alert('Error sending sms!');
});
});
}
})
在上面的代码中,当我使用intent:'INTENT'选项时,我能够使用我的设备的默认短信应用程序发送短信。但是当我使用intent:''选项时,我无法在我的应用程序中发送短信。错误消息显示在设备中。
答案 0 :(得分:0)
此代码在我的iPhone和Galaxy S4上运行完美。它位于我的控制器内部,并从UI获取学生对象和消息。它应该非常简单。
function sendMessageToParent(student, message) {
$cordovaSMS.send(student.phone, message)
.then(function () {
$log.log('Message sent.');
});
}
注意我根本没有设置任何选项。我正在使用Ionic-Native SMS库通过他们的Bower包与Ionic 1.3。 http://ionicframework.com/docs/v2/native/sms/ 这个插件与你正在使用的插件相同:https://github.com/cordova-sms/cordova-sms-plugin