IOS APNS remote push, how to control the angle mark offline after App is dropped by kill?

problem description

when you do IM live chat, when you receive a message, you will display a small red corner sign on the icon of App, and there are several unread messages. Then the chat list shows the number of unread messages for a specific person, and the total number of messages pushed is the total number of messages pushed. It seems that there is no problem with the logic that the corner mark for reading someone"s messages is how many messages have been read and how many messages have been subtracted. When app is not started, or press the home button to exit to the background kill and drop app, you can still receive a notification message. Just at this time, the corner mark will not increase progressively, and searching Baidu and google, is still fruitless:

the environmental background of the problems and what methods you have tried

  1. the App, of a process that is not started or dropped by kill cannot be incremented into the code in App, so it can only be set through the server badge field
  2. .
  3. through the server setting, the server needs to know how many messages have been read by the client and has to report the number of unread messages. At this time, the answer seems to be very clear, so let"s do it
  4. Silent push has no message display or sound. It is said that silent push can perform background tasks for dozens of seconds, but each push comes to an abrupt end (once every 3 seconds in a background cycle). Later, it was learned that Apple stipulates that background tasks can be used a limited number of digits within an hour. So. I don"t know what to say (but Wechat"s news corner mark can always be increased).

something terrible happened, that is, when the flight mode is enabled, all unread messages are read off, and then exit to the background kill drop App, and then dozens of messages are crazily pushed by the backend. At this time, the number of unread messages has not been reported in time, so this operation will cause inconsistency between the front and back ends of unread messages, and users will be disgusted if they feel that the data is abnormal. Uninstall App and other operations

because Wechat has achieved this function perfectly, I don"t know how they achieve it, so this is very embarrassing.

what result do you expect? What is the error message actually seen?

look forward to netizens to provide ideas, thank you in advance


first of all, your first step is wrong. The specific message unread is not calculated on the mobile end, but is transmitted to the mobile end by the background statistics. When a new message appears, send a push to APP and pass the new corner value. The advantage of this is that regardless of whether the APP exists in the background or is dropped by the Kill, the APP can receive the appropriate push notification and change the corner label. This is also a big advantage of APNS.
next, after entering APP, the user first gets the corner value passed by the backend and saves it in the plist file in sandboxie of APP. If the user clicks on the unread message, the number of corner marks in the plist file is reduced by one and reported to the backend. When the user manually kills APP or APP to enter the background, then set the number of corners saved in the plist file to the current number of corners.

iOS developer rookie, this is my method of operation, for reference only.

Menu