我正在尝试使用 cordova
构建一个包装应用程序并使用 PHP
作为服务器后端。
我正在使用 cordova-plugin-fcm
来处理推送通知。
如果我错了,请纠正我,每个设备(android 和 ios)都有自己的 id,用于发送通知。
如何获取该 ID 并将其发送到 PHP
路由,以便我可以将其与登录用户绑定(bind)并发送通知?
//FCMPlugin.onTokenRefresh( onTokenRefreshCallback(token) );
//Note that this callback will be fired everytime a new token is generated, including the first time.
FCMPlugin.onTokenRefresh(function(token){
alert( token );
});
在上面的示例中,token
是要发送到 PHP
以发送通知的 id?
device.uuid
可以用于发送通知吗?
我已经设置了 Firebase
配置,并且项目已设置 google-services.json
和 GoogleService-Info.plist
。
谢谢
最佳答案
Firebase Cloud Messaging 将其消息定位到特定设备上的特定应用。每个特定的应用安装均由 Firebase 的实例 ID 进行标识,也称为设备注册 token 或 FCM token 。
Firebase 文档 accessing the registration token对此是这样说的:
On initial startup of your app, the FCM SDK generates a registration token for the client app instance. If you want to target single devices or create device groups, you'll need to access this token by extending
FirebaseMessagingService
and overridingonNewToken
.
快速阅读 Cordova documentation on device.uuid ,这似乎只是识别设备,而不是设备上的应用程序。由于 FCM 消息传送到每个设备上的特定应用,因此您似乎不太可能使用设备的 UUID 作为替代。
即使 UUID 对于每台设备上的每个应用都是唯一的,它也不会是直接替代品,因为 FCM 仅适用于其自己的注册 token 。至少您需要保留 device.uuid
值与其相应 FCM token 的映射。
关于android - Cordova 的 device.uuid 值可以用于发送 Firebase 推送通知吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57905825/