expo push notifications how to unsubscribe from notification channel

  expo, php, react-native-push-notification

i am trying to setup expo push notifications and i want when the user logs out from their account in the app , then they will be unsubscribed from the notification channel and no longer receive notifications. this is my notification code:

async function registerForPushNotificationsAsync() {
let token;
if (Constants.isDevice) {
  const { status: existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS);
  let finalStatus = existingStatus;
  if (existingStatus !== 'granted') {
    const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
    finalStatus = status;
  }
  if (finalStatus !== 'granted') {
    alert('Failed to get push token for push notification!');
    return;
  }

  token = await Notifications.getExpoPushTokenAsync();

} 

return token;

}

and this is where i subscribe them to their chanels using php

   $channelName = 'default';
$recipient= 'ExponentPushToken[K2eocNGQQF5yM5fIxeIQzt]';

$expo = ExponentPhpSDKExpo::normalSetup();

$expo->subscribe($channelName, $recipient);

$notification = ['body' => 'test'];

$expo->notify([$channelName], $notification);

Source: Ask PHP

LEAVE A COMMENT