【问题标题】:Expo Notification世博会通知
【发布时间】:2019-03-25 07:37:31
【问题描述】:

我正在为我的应用程序使用 expo 通知,它在 ios 上运行良好,但在 android 上不起作用。我进行通知的方式是通过以下代码获取密钥

const { status: existingStatus } = await Permissions.getAsync(
          Permissions.NOTIFICATIONS
        );
        let finalStatus = existingStatus;

        // only ask if permissions have not already been determined, because
        // iOS won't necessarily prompt the user a second time.
        if (existingStatus !== 'granted') {
          // Android remote notification permissions are granted during the app
          // install, so this will only ask on iOS
          const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
          finalStatus = status;
        }

        // Stop here if the user did not grant permissions
        if (finalStatus !== 'granted') {
          return;
        }

        // Get the token that uniquely identifies this device
        let token = await Notifications.getExpoPushTokenAsync();
        alert(token)

然后将令牌保存在服务器中并发送如下通知:

发帖方式 https://exp.host/--/api/v2/push/send

{
  "to": "ExponentPushToken[HOKJqEF5FdGLRO7s-Kg4Ns]",
  "title":"Test",
  "body": "Test"
}

我是否必须使用 firebase FCM 才能使其在 Android 中运行?

【问题讨论】:

    标签: android notifications expo


    【解决方案1】:

    根据expotutorial,FCM不需要在android上使用Expo推送通知服务,除非你想创建APK来发布。

    我已经创建了一个snack进行比较,您可能需要安装了expo的真实设备来获取推送令牌。致电https://exp.host/--/api/v2/push/send 时,您应该会收到如下回复:

    {
        "data": {
            "id": "a0c9af62-5b56-449e-aaea-51bee782dd3d",
            "status": "ok"
        }
    }
    

    【讨论】:

      【解决方案2】:

      是的,如果您想在 Google Play 商店中发布您的应用 - 这就是重点。在 expo 应用程序中,它还使用 FCM。

      expo push notification documentation page 不是很清楚地提到,推送通知需要几个步骤才能在独立的 android/ios 应用程序中工作。虽然它在文档中提到页面底部的“下一步”,但从第一段来看,并不清楚它们是否将 expo 应用程序通知与独立的 android/ios 应用程序通知区分开来。相反,它觉得 Expo 会处理所有事情,就好像独立应用程序不需要更多步骤一样。它当然只适用于 Expo 应用程序。但是,当我们进入 Next Steps 页面时,我们会在“凭据”部分找到最重要的信息。

      这就是它适用于 Android Standalone 应用程序的方式(我已经这样做了)。我们需要设置我们自己的 Firebase 项目,正如这里所说的 Using FCM for Push Notifications。如果您使用 Expo 服务器发送推送通知,请确保按照“上传服务器凭据”的步骤进行操作。您将看到在您的 Expo 凭证中添加了 FCM 服务器密钥。

      这不应该花费太多时间,但对我来说,设置这些额外步骤需要 1 个小时左右,因为我是第一次学习这些。

      【讨论】:

        猜你喜欢
        • 2021-03-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-14
        • 1970-01-01
        • 2022-06-19
        相关资源
        最近更新 更多