Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 发送两条或多条短信时出错_Javascript_Android_Angularjs_Cordova_Ionic Framework - Fatal编程技术网

Javascript 发送两条或多条短信时出错

Javascript 发送两条或多条短信时出错,javascript,android,angularjs,cordova,ionic-framework,Javascript,Android,Angularjs,Cordova,Ionic Framework,我正在使用Cordova SMS插件从使用Ionic开发的应用程序发送消息。当“friends”数组的长度为1时,将发送SMS。但是当你有更多的信息时,有时信息没有到达,或者更糟的是,相同的数字会收到两条信息。这个代码有什么问题吗? 代码中有问题的部分如下: $rootScope.showLoading('Enviando mensagen(s)!'); var loopPromises = []; $rootScope.friends = [{ nome: 'Dav

我正在使用Cordova SMS插件从使用Ionic开发的应用程序发送消息。当“friends”数组的长度为1时,将发送SMS。但是当你有更多的信息时,有时信息没有到达,或者更糟的是,相同的数字会收到两条信息。这个代码有什么问题吗? 代码中有问题的部分如下:

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

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
     });
}
var选项={
replaceLineBreaks:false,//true以替换\n新行,默认为false
安卓:{
intent:'intent'//使用本机android短信发送短信
//意图:“”//在不打开任何其他应用程序的情况下发送SMS
}
};

对于(var j=0;jI),已添加选项字段并进行了一些更改。请尝试一次,然后让我知道。