I've seen a bunch of questions about getting the correct iOS app badge number in response to a remote notification (like this , this , and this ). They all hinge on realizing that the OS will badge the app with the number in the payload before your app does anything. I get that, but my question is a bit different.
Assume the following series of events for an app that's enabled the "remote-notification" background mode (and otherwise properly configured for remote notifications):
Maybe no big deal if the user comes into the app right away, but I'd like the badge to be correct if they don't. Can I set the badge number from within application:didReceiveRemoteNotification:fetchCompletionHandler:
while executing in the background?
This article suggests you can change the badge if you asked for the "background fetch" background mode and the OS granted your wish. Any reason it shouldn't work if you're backgrounded to handle a notification?
For anyone who stumbles upon this later: I managed to get everything setup to actually try this out. Yes, you can mess with the app icon badge while in the background to handle a remote notification. At least when it comes to the badge, there's nothing special or restrictive about executing in the background due to a notification as opposed to any other background mode.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.