Is there a simple way to check if someone has registered for notifications on iOS and Android with the new notifications plugin? I am calling “notifications.registerForPushNotifications( { useFCM=true } )” basically on every launch of the app and it is starting to give me runtime errors.
notifications.registerForPushNotifications is required by iOS only. On Android this function does nothing as the registration is automatic.
On which platform are you seeing runtime errors, and can you post them here?
On iOS, what this function does is to ensure that the device is registered with a valid device token. One way to check if the device has a valid device token is to use notifications.getDeviceToken(). This function will return “unknown” if no device token has been registered for the device.
ingemar,
Do you know of a way to invalidate the token and cause android to regenerate a new one? (per below code)
We’re getting a lot of “NotRegistered” errors for device tokens we’re getting and we’re hoping we can reset them and get new ones generated when we detect that happening
do you mean GCM/FCM is returning ‘not-registered’ status for those tokens ? I get them all the time (for my android devices, for Apple i use APN directly). It is because users uninstall the app, or a new token has been issued to the app (maybe when app was updated). I won’t worry so much about those not-registered items, and just ensure I remove those token-ids from my database so I don’t send them again to GCM/FCM.
Did anyone find a workaround for this, or can explain what is going on for Android? I copy the token corona gives me and paste it into a php script to send a notification to an Android device and it will fail with “NotRegistered”. If I uninstall and reinstall then I can get a new token and it will work, but the token seems to be expiring after a week or so. My app has been using this code for years, but the tokens expiring quickly, seems to have started being a problem for about 6 months.
Firebase can change the device token at any time, however you should get a new “remoteRegistration” event when the app starts whenever that happens.
You can also manually retrieve the active device token by calling notifications.getDeviceToken(). This function will return “unknown” if no valid token has been assigned to the device.
My GCM/FCM tokens does not expire so fast. It usually changes when the app is updated. I get ‘NotRegistered’ If the app is no longer installed in the device.
May I know where is the documentation for this feature : notifications.getDeviceToken() ?
Been trying to look for it in https://docs.coronalabs.com/plugin/notifications-v2/index.html, but can’t find it.
Thanks
May I know where is the documentation for this feature: notifications.getDeviceToken()
Hmmm. The function is missing from the docs. I’ll make sure it’s added.
In the mean time the function exists in the plugin and it returns a string with the Firebase device token.
print( notifications.getDeviceToken() )
notifications.registerForPushNotifications is required by iOS only. On Android this function does nothing as the registration is automatic.
On which platform are you seeing runtime errors, and can you post them here?
On iOS, what this function does is to ensure that the device is registered with a valid device token. One way to check if the device has a valid device token is to use notifications.getDeviceToken(). This function will return “unknown” if no device token has been registered for the device.
ingemar,
Do you know of a way to invalidate the token and cause android to regenerate a new one? (per below code)
We’re getting a lot of “NotRegistered” errors for device tokens we’re getting and we’re hoping we can reset them and get new ones generated when we detect that happening
do you mean GCM/FCM is returning ‘not-registered’ status for those tokens ? I get them all the time (for my android devices, for Apple i use APN directly). It is because users uninstall the app, or a new token has been issued to the app (maybe when app was updated). I won’t worry so much about those not-registered items, and just ensure I remove those token-ids from my database so I don’t send them again to GCM/FCM.
Did anyone find a workaround for this, or can explain what is going on for Android? I copy the token corona gives me and paste it into a php script to send a notification to an Android device and it will fail with “NotRegistered”. If I uninstall and reinstall then I can get a new token and it will work, but the token seems to be expiring after a week or so. My app has been using this code for years, but the tokens expiring quickly, seems to have started being a problem for about 6 months.
Firebase can change the device token at any time, however you should get a new “remoteRegistration” event when the app starts whenever that happens.
You can also manually retrieve the active device token by calling notifications.getDeviceToken(). This function will return “unknown” if no valid token has been assigned to the device.
My GCM/FCM tokens does not expire so fast. It usually changes when the app is updated. I get ‘NotRegistered’ If the app is no longer installed in the device.
May I know where is the documentation for this feature : notifications.getDeviceToken() ?
Been trying to look for it in https://docs.coronalabs.com/plugin/notifications-v2/index.html, but can’t find it.
Thanks
May I know where is the documentation for this feature: notifications.getDeviceToken()
Hmmm. The function is missing from the docs. I’ll make sure it’s added.
In the mean time the function exists in the plugin and it returns a string with the Firebase device token.
print( notifications.getDeviceToken() )