0

I am working with expo notifications, everything works fine until I realized that somehow I need to update expo token by calling Notifications.addPushTokenListener as expo refreshes a new one and the older one will stop working. this is what I've done.

// with this I get an expo token Ok
let token = await Notifications.getExpoPushTokenAsync();
// type expo
{
    data: "ExponentPushToken[6CoxIjM15ilo2_ZDTWzeTh]"
    type: "expo"
}

// but when I want to retrieve on refreshed token I get an IOS token
Notifications.addPushTokenListener(function(response){
    console.log(response);
});
// I get an IOS type token and I do not need that, I need an expo token eventough I am in a ios physical device
{
    data: "a9ee9433ea8a3e883cb7f5f1eb0d1bada4eed5473713153534aa2abb5cf6268f"
    type: "ios"
}

What I need is a "expo" refreshed token instead of an IOS as I am working with expo.

Is the same token for expo push notifications? is "addPushTokenListener" called for for FCM/APN only?

Ivan Juarez
  • 1,413
  • 4
  • 21
  • 30

1 Answers1

1

Try calling getExpoPushTokenAsync() in the push token listener!

import * as Notifications from 'expo-notifications';

Notifications.addPushTokenListener(response => {
  Notifications.getExpoPushTokenAsync().then(expoTokenResponse => {
    // ... do stuff
  });
});

or

Notifications.addPushTokenListener(async () =>
  const expoTokenResponse = await Notifications.getExpoPushTokenAsync();
  // ... do stuff
});