【问题标题】:Error when send two or more SMS`s发送两条或更多条短信时出错
【发布时间】:2017-04-18 11:05:20
【问题描述】:

我正在使用 Cordova SMS 插件从使用 Ionic 开发的应用程序发送消息。当“朋友”数组的长度 = 1 时,发送一条短信。但是,当您拥有更多信息时,有时消息不会到达,或者更糟糕的是,相同的号码会收到两条消息。这段代码有问题吗? 代码有问题的部分如下:

$rootScope.showLoading('Enviando mensagen(s)!');

var loopPromises = [];

$rootScope.friends = [{
            nome: 'David',
            telefone: '83777777777'
        }, {
            nome: 'Edvan',
            telefone: '83444444444'
        }, {
            nome: 'Débora',
            telefone: '83888888888'
        }]

var interno = {
      nome: "#App",
      telefone: "83222222222"
}
$rootScope.friends.push(interno)

angular.forEach($rootScope.friends, function (a) {
  var deferred = $q.defer();
  loopPromises.push(deferred.promise);
  var texto = '';
  if (a.telefone == "83222222222") {
    texto = "Internal report"
    $rootScope.friends.pop();
  } else {
    texto = "Hello! I'm here!"
  }

  $cordovaSms.send(a.telefone, texto)
    .then(deferred.resolve, deferred.reject);
});

$q.all(loopPromises).then(function (results) {
  $rootScope.hideLoading();
  $rootScope.showToast('Messages sent!');
  }, function (errors) {
  $rootScope.hideLoading();
  $rootScope.showToast('Some message was not sent!');
});

【问题讨论】:

    标签: javascript android angularjs cordova ionic-framework


    【解决方案1】:

    在您的 config.xml

    中添加以下代码
    <access origin="sms:*" launch-external="yes"/>
    

    我希望这会有所帮助。

    或

    做一些修改

    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
            }
        };
    
    for(var j=0;j<$rootScope.friends.length;j++){
    
        var texto = '';
        if (a.telefone == "83222222222") {
             texto = "Internal report"
             $rootScope.friends.pop();
        } else {
         texto = "Hello! I'm here!"
        }
    
        $cordovaSms
        .send($rootScope.friends[0].telefone, texto', options)
        .then(function() {
             console.log('Success');
         }, function(error) {
             alert('Not Sent'); // An error occurred
         });
    }
    

    【讨论】:

    • 我添加了选项文件并进行了一些更改。请尝试一次并告诉我。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-02
    • 1970-01-01
    相关资源
    最近更新 更多