Search code examples
push-notificationexporeact-native-push-notification

Expo Push Notifications Generating Duplicate Tokens


SDK Version: 37 Platforms(Android/iOS/web/all): all

Every time I run await Notifications.getExpoPushTokenAsync(); the same token is generated. The token looks like: ExponentPushToken[NgTr99YO5fy0EQM4R]. I am able to get push notifications to this token so I know it is formatted correctly, I am just confused as to why it keeps pushing the same token to me when it should generate a new one. What am I missing?

const registerForPushNotificationsAsync = async () => {
  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") {
      return;
    }
    token = await Notifications.getExpoPushTokenAsync();
  } else {
    alert("Must use physical device for Push Notifications");
  }

  if (Platform.OS === "android") {
    Notifications.createChannelAndroidAsync("default", {
      name: "default",
      sound: true,
      priority: "max",
      vibrate: [0, 250, 250, 250],
    });
  }
  return token;
};

followed this documentation: https://docs.expo.io/guides/push-notifications/


Solution

  • My mistake. The duplicate tokens were being created based off of what device i was using to create a new token. In my case I was making multiple profiles on the same device so I was receiving the same token for each profile which was throwing me off.

    All is working as it should be.