Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Firebase push notification onTokenRefresh
Started by JTPenn Aug 04 2019 11:16 AM

1 reply to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

JTPenn

[GLOBAL: userInfoPane.html]
JTPenn
  • Contributor

  • 101 posts
  • Corona SDK

Sometimes for certain reasons the push notification token of certain users expire and get replaced with a new one

 

Monitor token generation

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, and log the value as shown:

@Override
public void onTokenRefresh() {
    // Get updated InstanceID token.
    String refreshedToken = FirebaseInstanceId.getInstance().getToken();
    Log.d(TAG, "Refreshed token: " + refreshedToken);

    // If you want to send messages to this application instance or
    // manage this apps subscriptions on the server side, send the
    // Instance ID token to your app server.
    sendRegistrationToServer(refreshedToken);
}

onTokenRefresh is useful so you can update the token stored on your server without requiring the user to open the app

How can I achieve this in corona sdk ?



[TOPIC: post.html]
#2

yosu

[GLOBAL: userInfoPane.html]
yosu
  • Contributor

  • 523 posts
  • Corona SDK

I don't know whether the getDeviceToken() function get's the updated token or not,

 

But i wouldn't worry so much because if you are using the old token to send FCM notification, FCM will report a new token in its response. Of course the old token still works (in my case). I think it is like a 'mismatch' keyword or something like that (you can see it in the FCM docs).




[topic_controls]
[/topic_controls]