Skip to content
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]: Unwanted dialog after allow notification permission #784

Closed
3 tasks done
tommylung opened this issue Nov 3, 2023 · 3 comments
Closed
3 tasks done

[Bug]: Unwanted dialog after allow notification permission #784

tommylung opened this issue Nov 3, 2023 · 3 comments

Comments

@tommylung
Copy link

tommylung commented Nov 3, 2023

What happened?

In Flutter SDK v5.0.3, here is the prompt for notifications when I first allow the notification permission.

Steps to reproduce?

1. Install SDK v5.0.3
2. Init OneSignal
3. Build app
4. Allow notification permission
5. Alert prompt

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
Screenshot 2023-11-03 at 6 03 04 PM

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?

  • iOS
  • Android

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@emawby
Copy link
Contributor

emawby commented Nov 6, 2023

@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?

@tommylung
Copy link
Author

@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();
  });
}

@tommylung
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants