The case is this:
- A user logs in to the app on their iPhone A
- The user login in to the same app on their iPhone B
Now, in the database, there are 2 tokens for one user, that is correct.
+---------+-------------------+
| user_id | device_token |
+---------+-------------------+
| 1 | 1st_device_token1 |
| 1 | 2nd_device_token1 |
+---------+-------------------+
Say, that user deleted the app, installed it again (on both devices) and that means, tokens in APNs changed, therefore in our database, there are 4 unique tokens.
+---------+-----------------------+
| user_id | device_token |
+---------+-----------------------+
| 1 | 1st_device_token1 |
| 1 | 2nd_device_token1 |
| 1 | 1st_device_token1_new |
| 1 | 2nd_device_token1_new |
+---------+-----------------------+
Now, a push notification for that user is going to be sent to 4 devices (4 tokens). If they keep deleting and installing the app (may happen :) ), I would have in the database a large amount of tokens for one user and think, that they have such a vast number of devices, while in reality, there are a lot of invalid tokens.
How to prevent that?