Search code examples
iosapple-push-notificationsapn

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!


Solution

  • 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.