世博会推送通知不适用于独立应用程序

Ant*_*eme 3 android push reactjs react-native expo

我使用 expo 推送系统设置了推送通知,通过 ExpoGo 使用该应用程序时效果很好。但在从 Play 商店安装的应用程序中,它不起作用。调试应用程序我发现

token = (await Notifications.getExpoPushTokenAsync()).data;
Run Code Online (Sandbox Code Playgroud)

没有返回任何内容,因为它之后的警报从未运行。

async function registerForPushNotificationsAsync() {
    let token;
    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;
    }
    alert('1')
    token = (await Notifications.getExpoPushTokenAsync()).data;
    alert('2')
    if (Platform.OS === 'android') {
      Notifications.setNotificationChannelAsync('default', {
        name: 'default',
        importance: Notifications.AndroidImportance.MAX,
        vibrationPattern: [0, 250, 250, 250],
        lightColor: '#FF231F7C',
      });
    }

    //sending the token to my api
    api.put('xxx', {
      notification_token: token,
    });
  }
Run Code Online (Sandbox Code Playgroud)

我应该怎么办?我有什么遗漏的吗?我刚刚使用了文档中给出的代码https://docs.expo.io/push-notifications/overview/

Ant*_*eme 5

我找到了解决方案。

关键是,在设置推送通知的文档中,由于某种原因,他们没有提到有必要设置一个 firebase 帐户来推送通知在独立应用程序中工作,即使我使用的是博览会系统。

在此链接中发现了解决方案https://github.com/expo/expo/issues/9770

并使用此链接设置 FCM https://docs.expo.io/push-notifications/using-fcm/