IONIC的Sendind SMS不适用于$cordovaSms插件

Sendind SMS from IONIC not working with $cordovaSms plugin

本文关键字:cordovaSms 插件 适用于 不适用 Sendind SMS IONIC      更新时间:2024-07-06

我正在使用smsCordova插件从我的离子应用程序发送短信,但收到了"短信未定义"的错误。我在$ionicPlatform.ready()函数中使用了cordovaSms插件。

这是我用来发送短信的代码:-

//use verifyNumber service
verifyNumberService.verify()
  .then(
    function (result) {
      if (result == "Successfully data save...") {
        //alert and navigate to profile Info state
        $ionicPopup.alert({
          title: 'Registered',
          template: 'Thanks For Signup'
        });
        $ionicPlatform.ready(function() {
          alert("in device ready function")
   sendOtp();
        });
        $state.go('profileInfo');
      }

这是sendOtp()的函数:-

 function sendOtp() {
    alert("inside send otp");
    $cordovaSms
      .send('+919765293765', "Hi there",{})
      .then(function () {
        // Success! SMS was sent
        alert("success")
        console.log('Success');
      }, function (error) {
        // An error occurred
        alert("error");
        console.log(error);
      });//then
   alert("send otp");
  }

Azhar Khan,如果我们想在cordova中使用发送短信请求,那么1.我们需要在您的应用程序中安装此插件:

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

2.需要在Controler函数中添加插件实例($cordovaSms):

.controller('ThisCtrl', function($cordovaSms) {
});
  1. 现在,我们可以在你的控制器内使用以下代码发送sms-throw插件:

document.addEventListener("deviceready",function(){

$cordovaSms.send('mobile_number', 'SMS Message', options)
  .then(function() {
     alert(SMS sent )
   }, function(error) {
     alert(Problem in sending SMS)
  });
});

这就是我们向离子中的任何号码发送短信所需要的全部祝代码日快乐。