-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error when send two or more messages #132
Comments
Hey @daviddguedes, I don't see anything wrong with your code. Have you figured this out? |
@dbaq I have not figured out what might be wrong. Still unsolved. |
I also face the same issue of the message either taking too long or one number receiving two messages.... |
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. WorkaroundIf 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. /**
* Send to next number when first succeed or fail.
*
* @param {array} numbers to send to
* @param {string} message to send
* @param {object} options to sms plugin
* @param {integer} [index=0] current index in numbers array
*/
function sendChained(numbers, message, options, index) {
index = (typeof index !== 'undefined') ? index : 0;
if (index >= numbers.length) {
return
}
sms.send(numbers[index], message, options,
function() {
console.log('notification.sendSms', numbers[index], 'ok')
sendChained(numbers, message, options, ++index)
},
function() {
console.error('notification.sendSms', numbers[index], 'failed')
sendChained(numbers, message, options, ++index)
}
);
} Call with sendChained(numbers, message, options) |
Yes, please loop over and call N times the |
@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. |
Ok I was thinking about another issue, I am reopening this. I will try to take a look soon. |
@gotling gave a good solution. Unfortunately those multiple instances in loop are too confusing and sometimes work erraneously. Why cant multiple numbers work like for this plugin: https://github.com/floatinghotpot/cordova-plugin-sms This above plugin doesnt support iOS hence i am forced to use your plugin. |
Hi @acedigibits, You can contribute by opening a PR in the meantime, cheers. |
I 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:
The text was updated successfully, but these errors were encountered: