简体   繁体   English

使用cordova和firebase推送通知云消息:registrationID不断变化

[英]push notification with cordova and firebase Cloud messaging:registrationID keep changing

Using cordova plugin ktekosi-phonegap-plugin-push , I get the registrationID 使用cordova插件ktekosi-phonegap-plugin-push ,我得到了registrationID

var push = PushNotification.init({ "android": {"senderID": "my sender ID"}});

push.on('registration', function(data) {
    console.log(data.registrationId);
    document.getElementById("fcm_id").innerHTML = data.registrationId;
});

So I can use it by the server to send notification through FCM. 因此,服务器可以使用它通过FCM发送通知。

How can I get this registrationID fixed for all time? 我如何一直固定使用这个registrationID Is this an app specific ID or a user specific ID? 这是应用程序专用ID还是用户专用ID?

Push registration ID will be changed with time. 推送注册ID将随时间更改。 This is an usual case. 这是通常的情况。 This is neither an instance of the installed application nor app-specific or user-specific id. 这既不是已安装应用程序的实例,也不是特定于应用程序或用户的ID。

When an app comes online you need to fetch the push registration ID and then pass it to your backend server each time to keep your backend server updated with the push registration ID. 当应用程序上线时,您需要获取推送注册ID,然后每次将其传递到后端服务器,以使您的后端服务器使用推送注册ID进行更新。

Your backend server will then generate a push notification and will send it to FCM with the specific push registration ID it has. 然后,您的后端服务器将生成一个推送通知,并将其具有特定的推送注册ID发送到FCM。 FCM then manages receiving the push notification in your mobile application. 然后FCM管理在您的移动应用程序中接收推送通知。

I've answered a question here telling how push notification system works. 我在这里回答了一个问题,告诉您推送通知系统如何工作。 You might have a look. 您可能会看一下。

Update 更新资料

Looks like google has changed its new gcm library as the answer stated here - https://stackoverflow.com/a/16839326/3145960 . 看起来谷歌已经改变了其新的GCM库作为回答说在这里- https://stackoverflow.com/a/16839326/3145960 You might take a look at here. 您可以在这里看看。 So, as I've read, the push registration id is updated only when app receives an update or the android os gets updated. 因此,据我所读,仅当应用收到更新或android os得到更新时,推送注册ID才会更新。 Its much simpler now. 现在要简单得多。

Try to use this plugin "cordova plugin add cordova-plugin-fcm". 尝试使用此插件“ cordova插件添加cordova-plugin-fcm”。 You can find detail here 您可以在这里找到详细信息

To get Registration ID Use it like this 获取注册ID像这样使用

<script type="text/javascript">
          function onLoad() {
          document.addEventListener("deviceready", Fire, false);
                               }

            function Fire() {

                FCMPlugin.getToken(
                  function (token) {

                       alert(token)
                  },
                  function (err) {
                           alert("Error: " + 'error retrieving token: ' + err);
                  }
                );

            };


        </script>
 <body onload="onLoad();">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 firebase 云消息推送通知 - firebase cloud messaging push notification Firebase云消息传递Android推送通知不起作用 - firebase cloud messaging Android push notification not working 使用云消息传递Firebase推送通知 - Push notification using cloud messaging firebase 使用Firebase和Google Cloud Messaging推送通知 - Push Notification using Firebase and Google Cloud Messaging Firebase推送通知云消息传递如何访问附加数据作为通知 - Firebase push notification cloud messaging how to access Additional Data as Notification Android RegistrationId 推送通知 - Android RegistrationId push Notification 无法使用 Firebase 云消息传递向 Android 设备发送推送通知 - Unable to send push notification to android device using firebase cloud messaging 使用 Asp.Net 的 FCM(Firebase 云消息传递)推送通知 - FCM (Firebase Cloud Messaging) Push Notification with Asp.Net 如何使用Firebase Cloud Messaging在Adobe Phonegap中执行推送通知 - How to perform Push Notification in adobe Phonegap using Firebase Cloud Messaging 从 Firebase Cloud Messaging 控制台发送带有 URL 的 Flutter 推送通知 - Sending a Flutter push notification with a URL from Firebase Cloud Messaging console
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM