I tried unregistering and re-registering to force GCM token refresh. But it did not refresh the GCM token. (I use GCM to send push notifications.)
- I registered (init the plugin) and sent push notifications. App received notifications.
- I unregistered and sent push notifications to the app. App did not received push notifications.
That is expected.
But the problem is I thought I would get get "NotRegistered" error from FCM as the response
when calling FCM end-point. Instead it returned a messageId. That means notification is send
from FCM but OS did not showed it in the device.
- I waited for 15 minuted and sent notifications. But still same behavior.
- I registered (init the plugin) again and plugin returned the old GCM token. I though I would get a
new token. I sent notifications and app received notifications. That means token is not
refreshed.
Problem is in iOS. It works fine in Android. Android returned a new token.
Plugin version: 1.8.4 (We are still using ionic 1. Cannot migrate to newer version right now)
iOS: tested in 8.4 and 11.0.3
Question: How I can force refresh GCM token in iOS?
Thanks :)
I checked the code and found that
Android:
When unregistering, token is deleted by InstanceID.getInstance(getApplicationContext()).deleteInstanceID();
but iOS:
[[UIApplication sharedApplication] unregisterForRemoteNotifications];
I Googled and checked how I can delete and refresh the token in iOS.
I found that I need to do this (code below) to delete and get a new token in iOS.
GGLInstanceID *iid = [GGLInstanceID sharedInstance];
GGLInstanceIDDeleteHandler deleteHandler = ^void(NSError *error) {
if (error) {
// failed to delete the identity for the app
// do an exponential backoff and retry again.
} else {
// try to get a new ID
dispatch_async(dispatch_get_main_queue(), ^{
GGLInstanceIDHandler handler =
^void(NSString *identity, NSError *error) {
if (error) {
// failed to get the identity for the app
// handle error
} else {
NSString *instanceID = identity;
// handle InstanceID for the app
}
}
[iid getIDWithHandler:handler];
});
}
}
[iid deleteIDWithHandler:deleteHandler];
(Refer https://developers.google.com/instance-id/guides/ios-implementation)
Question is how to do it without editing the plugin 1.8.4 version. May be I can create a custom plugin to delete the GCM token? Please help.
I tried unregistering and re-registering to force GCM token refresh. But it did not refresh the GCM token. (I use GCM to send push notifications.)
That is expected.
But the problem is I thought I would get get "NotRegistered" error from FCM as the response
when calling FCM end-point. Instead it returned a messageId. That means notification is send
from FCM but OS did not showed it in the device.
new token. I sent notifications and app received notifications. That means token is not
refreshed.
Problem is in iOS. It works fine in Android. Android returned a new token.
Plugin version: 1.8.4 (We are still using ionic 1. Cannot migrate to newer version right now)
iOS: tested in 8.4 and 11.0.3
Question: How I can force refresh GCM token in iOS?
Thanks :)
I checked the code and found that
Android:
When unregistering, token is deleted by
InstanceID.getInstance(getApplicationContext()).deleteInstanceID();but iOS:
[[UIApplication sharedApplication] unregisterForRemoteNotifications];I Googled and checked how I can delete and refresh the token in iOS.
I found that I need to do this (code below) to delete and get a new token in iOS.
(Refer https://developers.google.com/instance-id/guides/ios-implementation)
Question is how to do it without editing the plugin 1.8.4 version. May be I can create a custom plugin to delete the GCM token? Please help.