Different behaviors on iOS and Android
We have been trying to implement GCM on Android and iOS but there is a discrepancy on behaviors with the instanceID.
On Android and iOS when we request an instance ID every time we register our app we get the same token, this is true if we do not uninstall and install the app again, if we do that, we have a new instance ID on both, but the old android token becomes NOT_REGISTER and the old one on iOS is still working, leaving us to send 1 message the same Android device (ok) and 2 messages for the same iOS device (not ok)
Shouldn't the old iOS instanceID be NOT_REGISTER like it happens on Android?
Eventually the old Instance ID will be invalidated as well. However if you generate a new Instance ID you should replace the old one with the new one and stop sending to the old one. Also if you send to the old one, you should get a canonical id in the response indicating which token to use instead of the old one you just used.
Related
I am trying to write test cases to validate whether canonical IDs successfully replaced the original token without mocking.
I am unable to reproduce this from an android device. I tried to send my push notification with old registration id , I am only getting NotRegistered from FCM.
Any suggestions as to how to reproduce?
AFAIK, you no longer have to expect working with Canonical IDs (although having your server/client to be able to handle them would be good). Ever since FCM came into play, I haven't seen Canonical IDs being used anymore.
A portion from my answer here:
In FCM, it seems the Canonical IDs are no longer used (or at the very least extremely rarely) because of how the Instance ID service works. To put it simply, the service works that there would only be one valid token per App Instance.
If the older token expires (for whichever reason), FCM triggers a tokenRefresh event where you would get a new registration token, and where you must also handle it accordingly (in onTokenRefresh()).
I have several apps on Google Play that extensively use GCM and they have all been working very well for quite some time now. But, all of a sudden (Aug 12, 2015), GCM is sometimes returning "NotRegistered" when my server posts a message to it.
This is happening just occasionally but that is often enough to cause big problems as the messaging can no longer be trusted.
The last part of the web response stream is: [{"error":"NotRegistered"}]}
I log the registration id along with the response stream and the registration id that I attempted to use is the same one that has always been used for that phone. My apps get a new registration id when they are first ran so it is necessary for the application to be uninstalled and reinstalled to make the app work again. Has something changed?
Oddly, (or not) the problem has only occurred on phones running 5.1 lollipop. Did I possibly miss another breaking change?
Thanks,
Dean
If you are using GoogleCloudMessaging to register, one possibility is that these users received an upgrade of your app. See the latest edit to Eran's answer here.They will need to re-register with GCM. Consider using the latest registration method using Instance IDs, which has a listener for token refresh when needed.
I am having a weird issue with my app - I have two devices on which I test it. One is 4.4.4, second one 4.0.4. I have made one app which used GCM. It worked without a problem on both phones. Then I made a second one, which had the GCM module copy-pasted from the first one, without any changes.
Now, when I send GCM message to the KitKat phone, it receives it without problems. But I cannot get it on the second phone. It doesn't register it at all (BroadcastReceiver doesn't receive anything). All the while the first app is still working ok. Both phones have the exact apk installed via adb.
I store the GCM registration id in the phone, yet when I run the app on the KitKat, receive an ID, close app, erase data, run it again - I get a different ID second time. This doesn't happen with the second phone, which leads me to believe there has been some kind of error on the side of Google.
I stumbled on this thread, probably dealing with the same issue - GCM not working on Gingerbread, but is working on Ice Cream Sandwich. I tried reinstalling the app, but that didn't help, I am still getting the old (non working) GCM ID.
tl;dr I am unable to receive GCM messages on one phone, while the same app works on another. Probably a problem with registering GCM. Upon reinstallation I am still getting the same GCM ID. How to force Google to get me a new one?
EDIT: The answer below provided the info needed, yet it didn't fix the issue. I will open another thread to avoid misleading title.
I tore my hair out over this for two days... If you are using a device for testing, you need to delete the InstanceID before obtaining the token because once you overwrite your APK it de-registered that InstanceId for some reason... or something along those lines, it ended up working for me. So in your RegisterIntentService class, in the onHandleIntent function do the following:
InstanceID instanceID = InstanceID.getInstance(this);
try
{
instanceID.deleteInstanceID();
} catch(IOException e)
{
e.printStackTrace();
}
instanceID = InstanceID.getInstance(this);
I don't think getting a new registration ID would solve your problem, but here's the way I use to get a new registration ID :
Uninstall the app.
Send a GCM message to old registration ID. Repeat this step until you get a NotRegistered error in the response from Google.
Install the app again, which should re-register to GCM, and this time you should get a new registration ID.
I'm using this plugin (https://github.com/phonegap-build/PushPlugin) to send notifications to my users using my android app. Well, so far it's ok.
I have the following questions:
Every time the user opens my app I need to generate a new "RegID"? Or,is not necessary?
Because I'm saving the "RegID" in the database, for later make a shipping notification with PHP to the user's device.
What if every time open the app necessary generate a new "RegID" need to update my database alright?
Somebody can help?
No, you don't have to generate a new Registration ID in each launch of your app. You should only generate it the first time your app is launched (and it's also recommended by Google to generate it again when a new version of your app is installed).
Even when you request Google for a new Registration ID, you might get in response the same registration ID you already had, in which case make sure you don't duplicate that Registration ID in your DB.
I worked with Urban Airship push notifications using Tags. For every new installation UA mantain new
App ID under audience.In my application I have two options for login: 1.Male 2.Female
From UA I sended message by adding proper tag.
Case1:
At first installation, under audience my device registered with
selected tag(I logged as Male) and APP ID.
In this case everything works good.
Case2:
If I removed the app from device and install again and logged as
different User(Ex: female).
Now under audience my device registered with Female Tag and new App
ID. (Now My device registered with new APP ID under UA)
If I send push from UA by adding required Female Tag , push received
to my device.
But in few cases message from Male tag also received by device.
Observation:
Now under UA ,my device having two APP ID's with two different tags.
May be , by that reason my device received both tag messages
irrespective of selected Tags
Need solution:
Why android maintain new APP ID for every new installation?
How to remove previous APP ID of my device from UA before new installation
(OR)
How to override Previous APP ID with new APP ID
Note:
I installed application in my device with integrating push notification. Device registered with APID and keeps Active as True.
After re-installation of App, new APID generated and shown Active as True. But, previous APID's status of Active still maintained as True. Why previous APID's Active status not changed to False.
In IOS, after new installation previous Device Token's status changed to inactive. Why happen it in android only??
Thanks in advance..
Response from Urban Airship Support Team:
Android devices get a new APID whenever you uninstall and reinstall an app, just because of the way GCM works and how our system handles it. Our apologies if this is inconvenient for you, but yes, this is expected behavior. Once you try to push to the old APID, our system will realize that the earlier install is no longer active, and should mark the old APID as inactive. The new one will remain active.
If you uninstall and reinstall an app fast enough, you may experience behavior like you saw, where one last push to an old tag for the old APID gets through. The old APID will then be marked inactive by our library if this occurs, and it should not happen again for that installation. We find that this is extremely rare in production and is only ever an issue during testing.
If you want to manually deactivate the old APID that you know is no longer active, just push to it directly and GCM will give us feedback that it is no longer valid. We will no longer attempt to push to it after that point.
Finally, what version of our library are you using? Please make sure you are using the most recent version here: http://urbanairship.com/resources/developer-resources -- older versions did not handle this behavior as reliably.