Reputation: 8874
I am trying to send sms on loop with Cordova plugin. The issue that big part of SMS not sent. Dose cordova have some limitation or should I do some ideal time? this my code:
var contactsLen = $scope.contacts.length;
for (var i = 0; i < contactsLen; i++) {
if ($scope.contacts[i].hasOwnProperty('number')) {
$cordovaSms
.send($scope.contacts[i].number, text)
.then(function () {
if (i == contactsLen - 1) {
$scope.log += 'send All!'
}
}, function (error) {
Upvotes: 0
Views: 97
Reputation: 10857
The plugin code that sends the SMS is asynchronous, which means running it in a loop like that will not work the way you expect. If you want to fire multiple async events and wait for them all to finish, then you need to use something like q$ (https://docs.angularjs.org/api/ng/service/$q) to handle it. Make note of the all() method which lets you pass an array of promises.
Upvotes: 1