In fact, in iOS 10, the remote notification will automatically didReceiveRemoteNotification method in the AppDelegate application.
You have 2 ways to refresh the icon in the background.
I have done this for my current application. You do not need to expand the eithier notification service.
1st way
Send the APS badge key with your payload to APN.
This will update the icon counter according to your Integer value in your icon payload. eg:
// Payload for remote Notification to APN { "aps": { "content-available": 1, "alert": "Hallo, this is a Test.", "badge": 2, // This is your Int which will appear as badge number, "sound": default } }
2nd way
You can switch application application.applicationState and update your icons. When ApplicationState is in .background . BUT you should take care not to set the icon key parameter in your notification payload when sending to APN ex
// Payload to APN as silent push notification { "aps": { "content-available": 1 } }
Process update icon according to application state
Here is my working code for updating the badge counter without an icon in the APN payload.
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { print("APN recieved") // print(userInfo) let state = application.applicationState switch state { case .inactive: print("Inactive") case .background: print("Background") // update badge count here application.applicationIconBadgeNumber = application.applicationIconBadgeNumber + 1 case .active: print("Active") } }
Reset number of icons
Remember to reset the icon counter when your application returns to its active state.
func applicationDidBecomeActive(_ application: UIApplication) {
Gkiokan Nov 05 '18 at 17:58 2018-11-05 17:58
source share