Closed tommylung closed 11 months ago
@tommylung Hello thank you for reaching out. That prompt is typically shown when the app has requested permission after the permissions have already been rejected. Could you share your code setting up OneSignal? Is this always happening even for fresh installs (uninstall/reinstall) or is it only happening for overwritten builds or hot reloads?
@emawby Thanks for your reply.
Yes, this prompt always happens for fresh installs and cannot receive any notification from OneSignal.
Here is the code for setting up OneSignal. I implemented the code in a screen that after the main.dart
.
static void setOneSignal() {
//Remove this method to stop OneSignal Debugging
OneSignal.Debug.setLogLevel(OSLogLevel.verbose);
OneSignal.initialize(Constants.onesignalId);
OneSignal.Notifications.requestPermission(true);
OneSignal.User.pushSubscription.addObserver((state) {
debugPrint(state.current.jsonRepresentation());
debugPrint("[OneSignal] User ID: ${state.current.id}");
});
OneSignal.Notifications.addPermissionObserver((state) {
debugPrint("[OneSignal] Has permission $state");
});
OneSignal.Notifications.addClickListener((event) {
debugPrint(
'[OneSignal] NOTIFICATION CLICK LISTENER CALLED WITH EVENT: $event');
});
OneSignal.Notifications.addForegroundWillDisplayListener((event) {
/// preventDefault to not display the notification
event.preventDefault();
/// notification.display() to display after preventing default
event.notification.display();
});
}
I have changed OneSignal.Notifications.requestPermission(true);
to OneSignal.Notifications.canRequest();
and the dialog haven't shown again. I'm unsure whether this is a good practice or not.
What happened?
In Flutter SDK v5.0.3, here is the prompt for notifications when I first allow the notification permission.
Steps to reproduce?
What did you expect to happen?
It is expected that no alert will be prompted.
You currently have notifications truned off for this application. You can open Settings to re-enable them
Moreover, the devices cannot receive the push notification after upgrading to SDK v5.0.3. I can receive notifications from the previous SDK version.
OneSignal Flutter SDK version
5.0.3
Which platform(s) are affected?
Relevant log output
No response
Code of Conduct