How to test DeviceNotRegisteredError (Expo push notifications)

Hi all,

I have a question regarding handling errors when sending expo push notifications.

I seem to able to send notifications to my ios device just fine (in the normal case) via expo-server-sdk-python. However, does anyone know how (steps needed) to test the DeviceNotRegisteredError when sending Expo push notifications?

I tried:

  1. Disabling notifications in my ios app but then expo-server-sdk-python did not throw an error after sending. (status is “ok” and not “error” )
  2. Next I uninstalled my ios app and still expo-server-sdk-python did not throw DeviceNotRegisteredError after sending. (status is “ok” and not “error” )

Am I thinking about this right?

Even the Expo Push notification Tool doesnt seem to error (no DeviceNotRegisteredError seen) after performing the two steps in my last post and sending a push notification to the expo the same push notification that worked before uninstalling the app.

Hey @vtandon,

It will take some time to for APNS to identify and register that you disabled notifications for the app and mark the device as unregistered.


Ok interesting.Thanks for the info. Its been a few days and still no error sending to the old pushtoken. Do you know if its weeks or months later when APNS detects this?

I’m actually unsure. APNS docs may have some documentation on this. I would’ve suspected that 3 days would have been enough though.


We have also experienced this problem. We haven’t pushed to production yet and only have tested via expo + Test flight.

  1. Have you guys tested in production?
  2. We haven’t been able to reproduce the DeviceNotRegistered and are worried about getting blocked. @ide could you provide some background on how you came to the conclusion quoted in the expo-server-sdk-node repo?
    “// The receipts may contain error codes to which you must respond. In
    // particular, Apple or Google may block apps that continue to send
    // notifications to devices that have blocked notifications or have uninstalled
    // your app. Expo does not control this policy and sends back the feedback from
    // Apple and Google so you can handle it appropriately.”
  3. If we uninstall the app the phone doesn’t actually receive the notification but we still get “ok” from expo. I assume this is not expected behavior? Apple would still block for doing this even though the user is not seeing notifications?


(2) I don’t remember the specifics but IIRC the Apple and Google push notification docs said to stop sending notifications to devices that have been unregistered. Other parts of the Apple push notification system do have rate limiting built-in and it seems prudent to also be responsible when it comes to unregistered device tokens.

The Google docs say:

The provided registration token is not registered. A previously valid registration token can be unregistered for a variety of reasons, including:

  • The client app unregistered itself from FCM.
  • The client app was automatically unregistered. This can happen if the user uninstalls the application or, on iOS, if the APNS Feedback Service reported the APNS token as invalid.
  • The registration token expired. For example, Google might decide to refresh registration tokens or the APNS token may have expired for iOS devices.
  • The client app was updated, but the new version is not configured to receive messages.

For all these cases, remove this registration token and stop using it to send messages.

(3) It is expected behavior to sometimes receive “ok” when the client has uninstalled the app.

The Expo push notification service will return “ok” in the push tickets once the notification has been delivered to Expo, and may or may not return “ok” in the push receipts once the notification has been delivered to Apple or Google. You should be looking at both the synchronous push tickets and asynchronous push receipts that are made available later.

The status and other information in push receipts is based the response from Apple or Google. One thing to note is that neither service reports the actual delivery of the notification. They just report whether the Apple or Google servers successfully received the notification, not whether the client device received the notification. In turn, the push receipts do not specify whether the device received the notification.

After some time – perhaps on the next notification, or whenever Apple or Google’s servers learn that the device no longer will receive notifications – they will send back information saying the device is no longer registered for notifications. When this happens, the Expo push receipt will contain the DeviceNotRegistered code.

Thanks @ide for the quick reply. We’re definitely building our notification service around the error codes outlined in Expo docs to be responsible when it comes to unregistered device tokens. But since we’ve been unable to repro the DeviceNotRegistered error code, it’s good to know that your comment was not referencing a hard warning from Apple (but let us know if you find otherwise). The most relevant warning in Apple’s docs that we could find was:

" 4.5.4 Push Notifications must not be required for the app to function, and should not be used for advertising, promotions, or direct marketing purposes or to send sensitive personal or confidential information. Abuse of these services may result in revocation of your privileges."

We’ll continue to send notifications to one of our test devices where we’ve uninstalled our app, and update this thread (assuming it’s still open) as soon as we receive the DeviceNotRegistered code.

In your testing, have you ever seen the DeviceNotRegistered code, and if so, how long does it typically take after app uninstall / notification disabling before this code is received? Note that our main concern atm is iOS.

I’m not sure how long it takes to receive DeviceNotRegistered, but it is a very common error code system-wide. One, let alone 100, notification sent to a device that previously reported DeviceNotRegistered is not going to create an issue. As long as you handle it vs. not handling it at all, you should be fine.

1 Like

Thanks for the additional info @ide . Still sending to my old push token returns ok in with the push ticket response and push ticket receipt even after 10 days. This is even after sending new push notifications to the same device that we previously installed and uninstalled our app. So the old token should be invalid. We are still in development and not in production. I’d like to test end-to-end test that our server code to handles DeviceNotRegistered but currently that doesnt seem possible at this time :frowning:

Expo does not control when you get back DeviceNotRegistered. You could just locally mock out a response that has DeviceNotRegistered if you want to test it.

Weird…I found in my test case when developing this logic for my app was I get the DeviceNotRegistered error back immediately on the ticket response not the receipt.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.