-
Notifications
You must be signed in to change notification settings - Fork 197
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
[Bug]: optIn() and optOut() seem like they should return a promise that one can await
#967
Comments
Hi @kpturner, thanks for your question and I understand your feature request. The reason we don't have a callback to
If you call optIn and optOut one after the other, what happens depends on if When optIn is called, we set local state to "true" and then when optOut is called, we set local state to "false". Then when it is time to send the batched requests, the latest state is sent, so "false" is sent. If the device is offline or the SDK receives a 500 error, it will cache and retry the request again. So, it is not trivial to return promises to these methods. In the scenario with the 2 calls back to back, what should be returned to the first optIn call if we ultimately send only the optOut call. |
Hel @nan-li Thankyou for that explanation of what is going on under the covers. Then the explanation for what is causing a mismatch between what the app thinks the opt-in status is and what is showing on the dashboard may lay elsewhere. Firstly it seems likely therefore that calling If I start the app and call Can I assume also that as |
When and how does the app decide to send the batch updates? I have called |
I finally made it work by disallowing notifications on the device, then calling optIn which prompted me to allow notifications and THEN it updated the dashboard correctly. |
What happened?
Both the
optIn
andoptOpt
methods do not return anything and do not appear to be async. However, surely under the covers both are making an async communication with the OneSignal backend? This being so, it is not possible toawait
the outcome. It is possible to do lots ofoptIn
andoptOut
calls in a client app and not really know what the final outcome is, because there is no guarantee that the updates to the backend will be processed in the order that you executed them. For example, I could call optIn and optOut one after the other but the optIn request might be processed after the optOut. So the app thinks it is opted out when in fact it is not.This is the only explanation I can think of for the situation we have where the "opted in" status in OneSignal does not always match the last status update the app thinks it sent.
Why can we not
await
each of these calls so that we know that it has been received and processed?Steps to reproduce?
What did you expect to happen?
I would expect all methods that perform async requests to the OneSignal backend to return a promise that can be
await
ed.OneSignal Cordova SDK version
5.0.4
Which platform(s) are affected?
Relevant log output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: