使用通过 batchImport 获得的 FCM 令牌 (iOS)

Using FCM token obtained via batchImport (iOS)

我正在尝试迁移现有应用程序以使用 FCM。我获取了 APNS 令牌并将其发送到 "batchImport" 服务,使用 curl:

curl -H "Authorization: key=<auth key>" -H "Content-Type: application/json" -X POST -d "{\"application\": \"com.myco.myapp\", \"sandbox\": false, \"apns_tokens\": [\"410564ffd0aaf91dd06e8ab7b8362238e2c7f1bbd5a520d6afaff38c9b670a90\"] }" https://iid.googleapis.com/iid/v1:batchImport

我收到 "registration_token" 回复。 当我随后尝试使用该令牌请求推送通知时,它没有到达设备。这是其中的卷曲:

curl -H "Authorization: key=<Auth key>" -H "Content-Type: application/json" -d "{\"to\":\"<registration_token_from_above>\", \"notification\":{\"body\":\"First\", \"title\":\"Num 1\"}}" -X POST https://fcm.googleapis.com/fcm/send

我也无法从 Firebase 控制台中的 "Notification" 工具发送。

我根据此处的示例从头开始创建了第二个项目:https://github.com/firebase/quickstart-ios.git。这一个在 Firebase 控制台和 curl 上都有效。

Firebase 客户端代码中是否发生了一些神奇的事情,而当我使用 batchImport 服务时却没有发生?如果是这样,您将如何从不同的服务迁移到 FCM?

它是如何工作的?

在 Firebase 文档中找到:

An FCM implementation includes an app server in your environment that interacts with FCM via HTTP or XMPP protocol, and a client app. Additionally, FCM includes the Notifications console, which you can use to send notifications to client apps.

Firebase Notifications is built on Firebase Cloud Messaging and shares the same FCM SDK for client development. For testing or for sending marketing or engagement messages with powerful built-in targeting and analytics, you can use Notifications. For deployments with more complex messaging requirements, FCM is the right choice.

你会如何从不同的服务迁移到 FCM?

文档中有完整的 Migration Guide for iOS

将您的 GCM 项目导入为 Firebase 项目

1.In the Firebase console, select Import Google Project.

2.Select your GCM project from the list of existing projects and select Add Firebase.

3.In the Firebase welcome screen, select Add Firebase to your iOS App.

4.Provide your bundle name and optional App store ID, and select Add App. A new GoogleServices-info.plist file for your Firebase app is downloaded.

5.Select Continue and follow the detailed instructions for creating an xcworkspace file for your app and connecting to Firebase on startup.

在您的下游 curl 命令中添加 "priority":"high"; 另请注意 "title" 在 iOS 设备上不受支持。

使用 batchImport 创建的令牌发送通知的另一个可能问题:注意正确设置 sandbox 参数。我的通知因各种奇怪的错误而被拒绝——令牌无效、令牌未注册、APNS 凭据无效——直到我设置 sandbox: true.