Error when send two or more messages
See original GitHub issueI am using the Cordova SMS plugin to send messages from an application developed with Ionic. When the “friends” array has length = 1 the SMS is sent. But when you have more than that, sometimes the messages do not arrive, or worse, the same number gets two messages. Is there something wrong with this code? The problematic part of the code is as follows:
$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!');
});
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
"Error code 2" Can't send text messages
Please let us know if Advanced Messaging is turned on, go to Message App > Settings > Advanced Messaging > off. We recommend...
Read more >Top 6 Ways to Fix Message Not Sent Error on Android
Top 6 Ways to Fix Message Not Sent Error on Android · 1. Check SIM/Account Balance · 2. Enable Airplane Mode · 3....
Read more >Fix: Can't Send Text Message with T-mobile Error 2
If you can't send messages with T-mobile error 2, your phone might be too cluttered. · Try clearing the cache and delete some...
Read more >Why did the person I sent a message to get duplicate ...
This indicates that Twilio sent just one message to the carrier. If your user received more than one, that means there was a...
Read more >Error occurs when you send or receive an email message in ...
Lists various error messages that you may receive when you send or receive ... Method 2: Make sure that your Outlook email account...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@dbaq Just looping over is not enough as multiple async calls to the underlying send function will be done, and the end result of that is unreliable. Doing the calls in sync does work.
I noticed the same unreliable behavior when sending to multiple numbers. Interesting enough the plugin actually expects an array of numbers which it internally remakes into a comma or semicolon separated string before sending of to Android. But at least in my environment only the first number in the array receives the message.
See sms.js and Sms.java
Workaround
If waiting until the previous message was sent, successful or failed, before sending to the next number, everything works ok. I made a recursive function that does just that.
I need to support older devices so I have not used any nice ES6 features.
Call with