How to toggle push-notifications ONN/OFF in expo app

SDK Version: 40
Platforms(Android/iOS/web/all): Android and iOS

Is there any standard way to provide the user with a toogle button to ONN/OFF push-notifications. I am using expo-notification package.

If there is no standard way, Is there any other hacky way of doing this?

Thanks for you time and help.

Hey @prince123abc, can you elaborate on what you mean by toggling on and off? Such as revoke or grant permissions at an OS level? Toggle the ability to show notifications while in-app? Etc? The specific context will determine the answer.

Cheers,
Adam

Hi @adamjnav, if the user toggles ON notifications he will be getting push notifications and not if he turns them OFF, regardless of whether the app is in foreground or background.

@prince123abc I think you’ll want to create a setting of your own. Check it before sending notifications or in the handler.

Thanks, I used a state variable for storing a boolean to specify whether to show an alert or not.

const [receiveNotifications, setReceiveNotifications] = useState(true);

Notifications.setNotificationHandler({
  handleNotification: async () => ({
    shouldShowAlert: receiveNotifications,
    shouldPlaySound: false,
    shouldSetBadge: false,
  }),
});

This also helped, just in case someone else need it.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.