Canonical IDs for iOS notifications over GCM - ios

We have a server to send notifications to our users on iOS and Android. Android works fine.
The problem is, when an user uninstalls and reinstalls our app. The app then requests a new push ID from GCM with its APNS ID(which is still the same) and sends us the new ID. Now we have 2 records to send notifications to. It looks like GCM just maps its generated ID to APNS ID in a simple N:1 relation.
If we had the same situation in Android and we now send our notifications to GCM, it would send the canonical ID in the first response, so we can react to that to not send a second notification. But with iOS it does not. The response looks like a normal, complete, successful request.
Did we miss something or didn't GCM implement canonical ids for iOS? I couldn't find any information regarding this problem.

A registration token is per device per installation.
Every time you uninstall and reinstall your app (either iOS or android), GCM will give you a new registration token.
It is a similar concept to Canonical IDs. If you get a Canonical ID, then you need to replace your old registration token in your server with the newly returned Canonical ID, as eventually the old registration token will stop working.
So, if you get a new registration token back when you uninstall and reinstall your iOS app (or Android app), you can simply compare the newly returned token with the old one. If the new token is different from the old token, then you can just replace the old one with the new one in your server so that you dont need to maintain 2 tokens in your server.

Related

Removing users who deleted app from database - iOS

I currently have a table in a mysql database with all the apn tokens of the users of my iOS app.
Every 24 hours my server runs a script that sends a notification to each user in the table.
I am sure some users are no longer active/have deleted the app and I was wondering if there is a way to identify them/remove them from this table?
The notification involves making a call to a weather api service (which is not free) so I am trying to avoid making unnecessary calls!
The Apple doc says if you get a
400
http code with
BadDeviceToken
as reason then
The specified device token is invalid. Verify that the request
contains a valid token and that the token matches the environment.
I check every response from the APN and invalidate/delete bad tokens from my database.
But you still need to do your weather request one more time for each device until its deleted from your DB.
You could send a silent notification before your request to check if the device token is valid, but that would be two notifications for one.

iPhone wallet not giving back device ID and Push token

I ran into a problem while integration "Registering a Device to Receive Push Notifications for a Pass" web service on my server for Apple Passes.
Link Below: https://developer.apple.com/library/content/documentation/PassKit/Reference/PassKit_WebService/WebService.html.
I've followed the following steps:
Able to successfully generate and distribute Apple Pass on iPhones through a downloadable link.
Once pass is downloaded, I'm adding that pass to Apple Wallet. While adding, Registration web service is called which must send my server a Device ID and Push Token, but I am getting these two parameters as nil.
However when I'm hitting the same URL on AdvanceRestClient(with dummy Device ID and Token), I do get the callback.
I wanted to know why I'm not getting device Id and Push token from iPhone??

How do I use an iOS APNs Auth Key with Azure Notification Hubs?

I've successfully setup my hub to use an SSL certificate per app, but I'd really like to move to the token-based APNs Auth Key approach. I configured my hub with I believe all the right information from the p8 file. For Key ID, I put in the 10-character value from when key was generated. For App ID, I put in my Team ID. For Token, I put in the private key value from the p8 file.
Has anyone had any success with this? Here's what happens when I attempt to send a test message:
When set to sandbox and I do a test send to my device, I get a failed outcome of "The Push Notification System rejected the request because of an invalid credential".
When set to production and I do a test send to my device, I get a failed outcome of "The Token obtained from the Token Provider is invalid"
For production, I think that is because I'm sending to a local app build outside of TestFlight/app store, so it is expecting the "development" or sandbox aps-environment.
Not sure what other troubleshooting I can do.
TIA,
I figured out what was happening for me.
The App Name field in the Azure Portal is critical to how the message gets delivered. Even though an APNs Auth Key can be used across multiple apps, the notification still must set the topic to be for that particular app. It seems like Azure Notification Hubs take the App Name field and put it into the apns-topic. Once I had that set to my app identifier, it worked as expected.
Also as an FYI, here is the link to the official documentation
https://learn.microsoft.com/en-us/azure/notification-hubs/notification-hubs-push-notification-http2-token-authentification

How to deal with refreshed Registration ID of Google Cloud Messaging on iOS?

I am developing an iOS application with notification by Google Cloud Messaging Service.(GCM).
I have been made android applications with GCM so am willing to make an iOS app of GCM notification(Not using APNS).
Questions came out about APNS token and GCM Registration ID.
Question #1
every time iOS App launches it checks if APNS token changes or updates when it changed. when APNS changes, does iOS app request 'new GCM Registration ID'?
Question #2
If Question #1 is right, should I just send new GCM Registration ID to my push server?
Question #3
Does GCM Registration ID change even if APNS token has not been updated at all?
Question #1 every time iOS App launches it checks if APNS token changes or updates when it changed. when APNS changes, does iOS app request 'new GCM Registration ID'?
Based from this documentation, when GCM registration token refresh is initiated from server side, the client app must handle a tokenRefreshed message with the GCM registration client/server handshake.
Question #2 If Question #1 is right, should I just send new GCM Registration ID to my push server?
Device tokens can change, so your app needs to reregister every time it is launched and pass the received token back to your server. Check this related SO question.
Question #3 Does GCM Registration ID change even if APNS token has not been updated at all?
According to this SO question, the registration ID will not change when token hs not been updated. "The only known cause for registration ID change is the old bug of apps getting unregistered automatically if they receive a message while getting upgraded. Until this bug is fixed apps still need to call register() after upgrade, and so far the registration ID may change in this case. Calling unregister() explicitly usually changes the registration ID too."

iOS Force GCM to refresh registration token

I use GCM in my Swift app and would like to ask GCM a new registration token.
I know that it's done automatically by GCM and I handle it in onTokenRefresh, but I want to know if it's possible to request GCM to refresh the token manually (to have a different one).
I tried to unregister for remote notification and register back to run the process (tokenWithAuthorizedEntity etc ...) but the registration token sent is the same.
any solution to do this ?
Use the deleteTokenWithAuthorizedEntity: method before asking for a new token as derived in the official docs. Also, if that fails, delete the Instance ID itself, which will delete all tokens associated with that Instance ID, in which case make sure to also call getIDWithHandler: before asking for a new token.
Anyway, why do you need to refresh this token? Although you can delete them, this is not their intended use. If you're just looking to ID a particular device uniquely, use the Instance ID itself OR use alternate methods of generating random strings (and then re checking if this random string has actually never been generated and used before).

Resources