Xamarin Form: Android using Firebase Cloud Messaging not receiving message

后端 未结 1 1648
囚心锁ツ
囚心锁ツ 2020-12-20 07:46

I have made the Firebase Cloud Message Notification working even work through the Notification Hub from Azure. The time I can\'t receive the message is when I try to re-run

相关标签:
1条回答
  • 2020-12-20 08:28

    Android using Firebase Cloud Messaging not receiving message

    As the GCM docs said :

    An ID issued by the GCM connection servers to the client app that allows it to receive messages.

    So only when the token is available, your app can receive message from GCM.

    How can an app get that token?

    You could see the document :

    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.

    The onTokenRefreshcallback fires whenever a new token is generated, so calling getToken in its context ensures that you are accessing a current, available registration token. Make sure you have added the service to your manifest, then call getToken in the context of onTokenRefresh

    Every time when you re-run the application in your device the token is changed, but as the document said, OnTokenRefresh is only called when the system determines that the tokens need to be refreshed, it is needed for key rotation and to handle Instance ID changes due to :

    • When the app is installed or uninstalled.
    • When the user deletes app data.
    • When the app erases the Instance ID.
    • When the security of the token has been compromised.

    You need to trigger OnTokenRefresh method. You should first uninstall the app from the device, then reinstall the app and open it, the OnTokenRefresh will be triggered and the token will be updated and your app could receive GCM message again.

    0 讨论(0)
提交回复
热议问题