Raunak
Raunak

Reputation: 3414

APNS service sending 200 for expired device token?

I am testing Apple Push Notification service (sandbox mode) before integrating in my app. We will potentially be sending out Push Notifications in the order of thousands per minute - so one of the major requirement is to not send notifications to an Invalid(deleted) device token if an app is deleted (or re-installed).

The device token, received in:

application(_ application: UIApplication,didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)

in App Installation specific. A new installation creates a new token and the previous one becomes invalid.

As per Apple's APNS document, sending a request for an expired device token should return:

410 The device token is no longer active for the topic.

However, I am consistently getting 200 for both valid and expired device tokens. The notifications for correct device token are delivered to the device whereas the ones for Invalid (expired) tokens are not.

I am using, npm apn package on the server side and testing on a device running iOS 12.3.

Am I missing something here?

Upvotes: 1

Views: 956

Answers (1)

Derryl Thomas
Derryl Thomas

Reputation: 1568

I have noticed this too. I usually get a 200 response code and the following body for an invalid/expired token:

{
    "multicast_id": 7942205170696355362,
    "success": 0,
    "failure": 1,
    "canonical_ids": 0,
    "results": [
        {
            "error": "InvalidRegistration"
        }
    ]
}

I assume you will have to parse the response body and check the success or failure count to determine whether the notification actually delivered. If you get a failure, then remove token this from your DB(or wherever you store your tokens to send to) so that it doesn't attempt to send it to the same token again.

Upvotes: 0

Related Questions