【发布时间】:2021-12-12 01:58:00
【问题描述】:
过去几天我一直在使用 Azure 通知中心,尝试在 ASP NET 和 Dart/Kotlin 中设置推送通知。我一直在为 FCM/PNS 令牌苦苦挣扎。
当我注册我的应用时,我会得到这个令牌:ddGYUP9OSdi2YR9Y******,使用 * 以防万一。
在开发过程中,我发现我有一个与 Hubs 相关的注册,其令牌为:ddGYUP9OSdi2YR9Y******:APA91bMANCn_SZQV8bUJCWOiyPzdXaBPrqLmqIk8ELj6RfCx5TKNR2hLmiNMfuyK7LdY70-BtMxxyRbituhPH2t5v9p0A-8qkCleEgOWi4cXcvKpxedW2QmqEmym-hk8oZOXdx-*****
它是相同的标记,但在分号后添加了一些内容。这是什么,它来自哪里?
我从FirebaseInstallations.getInstance().id 获得第一个令牌,并且我注册的每个设备的令牌长度都相似。但是,在我的 ASP NET 项目中,向设备发送通知仅适用于较长的令牌。当我使用 Firebase 控制台测试通知时:Firebase - Engage - Cloud Messaging - Compose Notification,只有长的有效。这让我相信我的注册码有问题。
那么短标记上冒号后面的额外内容是什么?
我为感兴趣的人获取 FCM 令牌的代码。
private fun getDeviceToken() : String {
if(!playServicesAvailable) {
throw Exception(getPlayServicesError())
}
val token = PushNotificationsFirebaseMessagingService.token
if (token.isNullOrBlank()) {
throw Exception("Unable to resolve token for FCM.")
}
return token
}
【问题讨论】:
-
您从 FirebaseInstallations.getInstance().id 获得的短消息是
deviceId,而长消息是deviceId:token的组合,用于引导推送消息到实际的设备应用安装组合。
标签: android firebase kotlin push-notification firebase-cloud-messaging