OneSignal-Flutter-SDK icon indicating copy to clipboard operation
OneSignal-Flutter-SDK copied to clipboard

Disable notifications

Open dheerajbred opened this issue 7 years ago • 6 comments

This is not an issue. I have been using this flutter plugin for 1 month. Everything is working well.

This is my initState code in my myhomepage.dart


@override
  void initState() {
    super.initState();
    _fetchData(1);
    _internetChecker();
    
    OneSignal.shared.init("********************************************", iOSSettings: {
          OSiOSSettings.autoPrompt: false,
          OSiOSSettings.inAppLaunchUrl: true,
          
        });
    OneSignal.shared.setInFocusDisplayType(OSNotificationDisplayType.notification);


    initDynamicLinks();
  }

I want to add a feature to the app setting page where user can choose to enable or disable notifications within the app. I have a separate settings.dart page where I want to set the control to receive notifications. How can I do this?

Thanks

dheerajbred avatar Sep 20 '19 17:09 dheerajbred

Check the setSubscription() method on OneSignal SDK documentations. You can simply disable notification using

await OneSignal.shared.setSubscription(false);

enricobenedos avatar Sep 23 '19 06:09 enricobenedos

Thanks for answering @enricobenedos

rgomezp avatar Oct 01 '19 01:10 rgomezp

@rgomezp is this the right behavior when setSubscription(false) and setSubscription(true) its will not receive the notification until you restart the app

elmissouri16 avatar Jul 19 '20 12:07 elmissouri16

Update:

Canceling or Resubscribing to Push Notifications has changed:

New methods:

await OneSignal.User.pushSubscription.optOut();

OR

await OneSignal.User.pushSubscription.optIn();

reisvini avatar Sep 12 '23 21:09 reisvini

@reisvini thanks brother you saved my day :)

Emranul-Islam avatar Oct 15 '23 07:10 Emranul-Islam

@reisvini

Thanks a lot.

eliasayele avatar Jul 19 '24 00:07 eliasayele