Our application works with GCM through which the server communicates with the device.

The question is, let's say, such a situation, the user uploaded our application, the server received the REG_ID device and marked it in the database.

It is clear that in the best case, when the user has access to the network and he removes the application, you can tell the server to update the information about the number of connected devices.

But what if the user does not have internet and he deleted the application ...?

How, then, to understand the current number of connected users?

Or should the entire database be divided into active and inactive, and once in a certain period of time (say, 1 day), check the user for communication or not?

    1 answer 1

    The most correct way is via "ping-pong" - that is, your server sends a specially crafted push and the client must respond to it (usually the server sends "ping", and the client answers "pong"). If the client does not respond for a certain period (for example, a week - this is already determined by managers who can evaluate the like), then the client goes into the "inactive" mode and after some time is deleted. How to find out when to remove? It is very simple - after the token’s life expires - the Google server responds that the token has expired.

    Tracking application removal is a bad idea. Suppose the user simply turned off the phone or dropped into the pool. The application is not available, but the user did not delete it.

    In more sophisticated systems, the user is provided with some kind of admin area, where he can "remove the device" or simply send a letter in the mail, where write "Your device is inactive for a week, we will soon remove it or run the application."

    • I did something like this ... Only somewhere in the Habré I read that it is also called heart beating ... Ok, you figure it out)) But please tell me more what you meant here Очень просто - по истечению жизни токена - сервер гугла отвечает, что токен "истек". Where can I read about it? I did not quite understand where Google server responds? and what is the validity of this token? And token is that you mean this ID that I get from GCM? - Aleksey Timoshchenko
    • Google’s server — GMC; Google’s server responds — responds to an attempt to opt for a push (perhaps you just don’t check the answer). what is the duration of this token - I have seen a day and a few days. I delayed that Google could easily "make them invalid", since I discovered an unauthorized use attempt. - KoVadim pm
    • Ok, so I have to do ping-pong and if there is no response for a week, then I transfer the user to inactive, then I check the token and if its validity period has expired, then I delete the user, right? And how often does Google update tokens and what is its default duration? - Aleksey Timoshchenko
    • I worked with it for a long time (several years ago) and saw a different time. I do not know the default time. Here they write that it looks like it already does not expire. To believe - I do not know. - KoVadim
    • But in general, you can conditionally take a week if the user does not respond, then send it to inactive, if a month has passed, then delete it ... How do you think such a tactic of norms? - Aleksey Timoshchenko