Open fmorau opened 9 months ago
Update:
Alternative described in Steps to reproduce?
section where I've used OneSignal.Notifications.requestPermission
- works.
So, it means, the issue is only in requesting permission not via OneSignal.Notifications.requestPermission
.
For example, in my case it is PermissionsAndroid.request
from react-native
library
Hi @fmorau,
Thanks for the update to your question. That makes sense, the OneSignal SDK does not know when you request permissions outside of the SDK's methods, and won't read data until a new session.
We are looking into this as a feature to support.
Hello @nan-li,
I hope you're doing well. I wanted to bring up an issue related to a functionality of this method and why I didn't use it.
I've encountered a situation where after selecting the "Refuse" option for push notifications permission, OneSignal.Notifications.requestPermission
still returns a "true" result (which means Authorized).
Additionally, trying to workaround it - I added check of OneSignal.Notifications.permissionNative
afterward (due to unexpected results) - it solved this exact issue, but failed in another case, when I granted permission and checked OneSignal.Notifications.permissionNative
, it still indicated a "Denied" status instead of "Authorized".
It's been a bit frustrating to work through these issues, and I would greatly appreciate any insights or assistance you might have.
P.S. I could solve it for now by using third party permission check method after OneSignal.Notifications.requestPermission
, but I assume you might want to fix it in upcoming releases
Thank you for your attention to this matter. π
@nan-li I could solve the main issue described above by requesting permission via OneSignal.Notifications.requestPermission
, but here is the case, which I could not "workaround"
Linking.openSettings
(from react-native library)turned on
, but the status of OneSignal.User.pushSubscription.getOptedIn
still remains as false
Even if OneSignal.User.pushSubscription.optIn
is calledAR: No message is shown
After the app is reopened, all notifications appear (even for the message sent at step 8)
Hi @fmorau, I apologize for the delay and thank you for the details.
I see there are 2 issues you are running into:
Question 1: This one I will investigate from our end and work on a fix, it seems for now you can workaround it.
I've encountered a situation where after selecting the "Refuse" option for push notifications permission, OneSignal.Notifications.requestPermission still returns a "true" result (which means Authorized). Additionally, trying to workaround it - I added check of OneSignal.Notifications.permissionNative afterward (due to unexpected results) - it solved this exact issue, but failed in another case, when I granted permission and checked OneSignal.Notifications.permissionNative, it still indicated a "Denied" status instead of "Authorized". It's been a bit frustrating to work through these issues, and I would greatly appreciate any insights or assistance you might have.
Question 2: The scenario you describe in the latest comment right above. I have some clarifying questions:
- Permission is requested after opening
You are calling OneSignal.Notifications.requestPermission
to do this? And it is called early in the app launch process?
- Go "In App" settings
- Enable notifications >> Modal to go to Phone app settings is shown
- User press a button to open settings, which executes Linking.openSettings (from react-native library)
This is your own app settings page and how are you asking them to "Enable notifications"? Is it through a OneSignal method? Are there any calls to OneSignal in these steps?
- User Enables notifications in app settings and comes back P.S. After coming back -> OneSignal properly notifies about permission turned on, but the status of OneSignal.User.pushSubscription.getOptedIn still remains as false Even if OneSignal.User.pushSubscription.optIn is called
The OneSignal.Notifications.addEventListener("permissionChange", (observer) => {})
observer is triggered? Did you ever call OneSignal.User.pushSubscription.optOut()
?
- User Receives a message
Sorry I misunderstand this. You send a message to the user but it is not shown on their device? And on the next app open, this notification is show by the device?
In the meantime, I think this is enough information for me to try and reproduce.
Hello @nan-li ! No worries, and thank you for taking care of it π I will try to answer your questions and if I will not be clear enough feel free to clarify.
OneSignal.Notifications.requestPermission
with custom permission check
, so it's not blocking.You are calling OneSignal.Notifications.requestPermission to do this? And it is called early in the app launch process?
Actually, in our case it happens long time after opening the app. User goes through sign-in / sign-up process until this method would be called.
This is your own app settings page and how are you asking them to "Enable notifications"? Is it through a OneSignal method? Are there any calls to OneSignal in these steps?
Yep, it is inside of our App. Whenever they want to enable/disable notifications we have specific "Settings" page for it. Whenever they try to turn it ON - we check programmatically if permission is granted on device level and if it is not - showing the modal (just react-native UI - not OneSignal method), which proposes to do it on device level first.
The OneSignal.Notifications.addEventListener("permissionChange", (observer) => {}) observer is triggered? Did you ever call OneSignal.User.pushSubscription.optOut()?
Yep, the subscription is triggered, when user returns back to the app, but getOptedIn
still returns false
even if optIn()
call would be added
No, we don't use OneSignal.User.pushSubscription.optOut()
method
Sorry I misunderstand this. You send a message to the user but it is not shown on their device? And on the next app open, this notification is show by the device?
Oh, sorry, it's indeed might not be clear enough,
8. Send messages to the device via Backend
should be more clear
The thing is that these messages shown as "delivered" on OneSignal
dashboard, but they will not be shown, until the app closed and opened back
Hi @fmorau,
Sorry for the delay, I haven't been able to reproduce and then I was out of the office the previous week.
Here are the steps I took. I built in debug mode using a Nexus S emulator on API 33. I do not have any 'settings' page within the app.
OneSignal.Notifications.requestPermission
and DENY. I do see the incorrect true
boolean you encountered and will look into this bug.OneSignal.Notifications.addEventListener('permissionChange', listener)
is triggered and returns true
.OneSignal.User.pushSubscription.addEventListener('change', listener)
is triggered and shows the optedIn
property change from false
to true
.
Does this issue happen consistently on every Android device you tested?
Following up on the other problem you encountered with using OneSignal.Notifications.requestPermission
, I was not able to reproduce the issue if permission is ACCEPTED using this method.
When I call OneSignal.Notifications.requestPermission
, the native prompt displays and I choose to accept the permission.
OneSignal.Notifications.hasPermission()
is true
.await OneSignal.Notifications.permissionNative()
is now Authorized
.await OneSignal.User.pushSubscription.getOptedIn()
is true
.I did not use other notification permission prompting methods.
Hello @nan-li,
Thank you for addressing this!
In response to your comment:
"I do not have any 'settings' page within the app."
I'd like to clarify the steps:
Linking.openSettings
from the React Native library.In essence, this means that the user triggers a Linking.openSettings
call, which opens the App Settings. You can simply add a button with a handler that calls Linking.openSettings
.
Regarding the consistency of this issue on Android devices - it occurs consistently on every Android device we've tested.
Hmm, ok maybe there is something strange with using Linking.openSettings
and OneSignal is not detecting something. I wouldn't think so, but I'll test using that method.
Also I am curious what happens if you don't use Linking.openSettings
... just go to native app settings directly and enable or disable the notification permission. Then, return to the app...?
^ Are the correct observers triggered and behavior is correct? Or behavior is still wrong, and same as using Linking.openSettings
?
Thank you for following up with your details all this time. It is appreciated.
Hello, @nan-li!
I've recently updated react-native-onesignal
in our app to the latest v5.0.3
with the fix you've made,
I retested all cases, and it worked very well!
Even with Linking.openSettings
and going back to the app after granting notifications permission - all worked! I've received permission change event and all data from OneSignal SDK were relevant π
Thank you for your involvement and congratulations for the great job you are guys doing!
Looks like we can close the issue now, Merci beaucoup!
But looks like I faced another one, one lever higher:
When I played further with turn on / off permissions and then open the app back to check if subscription and statuses are working well - it was indicating everything properly, But.... after enabling notifications and from inside the app it all looked good, inside my OneSignal app, I've seen this device with "permission not granted" label And messages were not coming π
@nan-li
Hi @fmorau,
When I played further with turn on / off permissions and then open the app back to check if subscription and statuses are working well - it was indicating everything properly, But.... after enabling notifications and from inside the app it all looked good, inside my OneSignal app, I've seen this device with "permission not granted" label And messages were not coming π
Can you explain more details?
In the app, it looks like the behavior is correct?... calling OneSignal methods like hasPermission()
and permissionNative
looks correct, the observers are triggering correctly?
But in the OneSignal dashboard, you see the subscription with the "Permission Not Granted"?
Can you reproduce your steps?
@nan-li yep, exactly! And even sometimes after I close and then open the app it still "Not Granted" and then with a couple more tries to close & open the state it suddenly changes
@nan-li should I log it somewhere as separate Issue, or you have already initiated process on it from within OneSignal Team?
I'm having getPushSubscriptionId
issues. It seems need to await for response. Because when i want to get the subs id, its just empty.
const deviceId = OneSignal.User.pushSubscription.getPushSubscriptionId();
console.log(deviceId); // this print nothing
Hi @fmorau I am so sorry for the delay.
I haven't been able to reproduce your new issue yet with toggling permission on and off outside of the application.
Do you happen to have logs to share? The Dashboard will show "Permission Not Grated" after the SDK tells the server that there is no permission. That means somehow, the SDK sent a request to the server with that information. All requests should be logged.
Hi @nusendra,
Sorry for the confusion.. The await
exists because we have to call into native Android methods to find the value, and it is not for waiting for the push subscription ID to be retrieved.
You can use the push subscription observer to be notified when it is retrieved. See usage for Push Subscription Observer in the migration guide here.
Hi @nusendra,
Sorry for the confusion.. The
await
exists because we have to call into native Android methods to find the value, and it is not for waiting for the push subscription ID to be retrieved.You can use the push subscription observer to be notified when it is retrieved. See usage const deviceId = OneSignal.User.pushSubscription.getPushSubscriptionId(); console.log(deviceId); // this print nothing.
I see, thanks. i will update my code later. Currently im using this solution https://github.com/OneSignal/react-native-onesignal/issues/1616
I see, also apologies I did not write my response correctly. I just updated my comment to use the correct link @nusendra
I see, also apologies I did not write my response correctly. I just updated my comment to use the correct link @nusendra
i believe i did that way before, but somehow it didn't work. But thanks, i'll try again. Maybe im missing something
What happened?
Hello
react-native-onesignal
team,I recently updated to v5.0.1 and experiencing an issue on Android where Push Notifications are not coming after first app opening. Whenever I collapse and expand the app - it starts coming.
I couldn't find any workaround to impact this behavior and enable notifications straight away, so I report it here. Any help or guidance would be greatly appreciated.
Thank you!
Steps to reproduce?
What did you expect to happen?
I expected that after updating to react-native-onesignal v5, push notifications on Android would continue to work as they did before the update.
React Native OneSignal SDK version
5.0.1
Which platform(s) are affected?
Relevant log output
No response
Code of Conduct