【问题标题】:How can I retrieve expo token instead of ios token when calling addPushTokenListener?调用 addPushTokenListener 时如何检索 expo 令牌而不是 ios 令牌?
【发布时间】:2020-08-24 22:43:16
【问题描述】:

我正在处理博览会通知,一切正常,直到我意识到我需要通过调用 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 时,我需要的是一个“expo”刷新令牌而不是 IOS。

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

【问题讨论】:

    标签: push-notification firebase-cloud-messaging apple-push-notifications expo expo-notifications


    【解决方案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
    });
    

    【讨论】:

      猜你喜欢
      • 2019-08-06
      • 2022-01-14
      • 1970-01-01
      • 2017-10-13
      • 2019-05-23
      • 2015-09-08
      • 2019-06-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多