无法获得博览会推送令牌

adi*_*ifi 5 android reactjs react-native expo

我正在构建一个基于 Expo 的 React 本机应用程序,我使用 Expo 的推送通知。当我使用 expo cli 测试应用程序时,我得到了 expo 令牌。在我生成一个 .aab 并将其发布到 Play 商店之后。我无法从任何设备获取 expo 令牌。我不知道为什么。

registerForPushNotification = async() => {
    // Check for existing permissions
    const {status} = await Permissions.getAsync(Permissions.NOTIFICATIONS);
    let finalStatus = status;

    // if no existing permission, ask user for permission
    if (status !== 'granted') {
        const {status} = await Permissions.askAsync(Permissions.NOTIFICATIONS);
        finalStatus = status;
    }

    // if no permission, exit the function.
    if (finalStatus !== 'granted') {
      alert('Failed to get push token for push notification!')
      return;}

    // get push notification token.
    let token = await Notifications.getExpoPushTokenAsync();
    alert(token)
    firebase.database().ref('/users/usersInfo/'+user).update({
      expoToken:token
    })

    if (Platform.OS === 'android') {
      Notifications.createChannelAndroidAsync('default', {
        name: 'default',
        sound: true ,
        priority: 'max',
        vibrate: [0, 250, 250, 250],
      });
    }
  }
Run Code Online (Sandbox Code Playgroud)

Bis*_*mad 6

为了对您的应用程序使用推送通知,您应该为 firebase 注册该应用程序。

如果您尚未为您的应用创建 Firebase 项目,请立即单击Firebase 控制台中的添加项目来创建。

在新项目控制台中,单击“将 Firebase 添加到您的 Android 应用”并按照设置步骤操作。确保您输入的 Android 包名称与 .android.package app.json

下载该google-services.json文件并将其放置在 Expo 应用程序的根目录中。

在您的 中app.json,添加一个android.googleServicesFile字段,其中包含您刚刚下载的文件的相对路径google-services.json。如果将其放在根目录中,则可能如下所示:

{
  ...
  "android": {
    "googleServicesFile": "./google-services.json",
    ...
  }
}
Run Code Online (Sandbox Code Playgroud)

现在您可以使用expo build:android -t apk应用程序包构建独立应用程序expo build:android -t app-bundle

文档中。