0

我正在处理博览会通知,一切正常,直到我意识到我需要通过调用 Notifications.addPushTokenListener 来更新博览会令牌,因为博览会会刷新一个新的,而旧的将停止工作。这就是我所做的。

// 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"
}

我需要的是一个“expo”刷新的令牌,而不是一个 IOS,因为我正在使用 expo。

世博会推送通知的令牌是否相同?是否仅针对 FCM/APN 需要“addPushTokenListener”?

4

1 回答 1

1

尝试调用getExpoPushTokenAsync()推送令牌侦听器!

import * as Notifications from 'expo-notifications';

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

或者

Notifications.addPushTokenListener(async () =>
  const expoTokenResponse = await Notifications.getExpoPushTokenAsync();
  // ... do stuff
});
于 2020-10-27T12:06:10.870 回答