Your notification payload should look like the following to update app badge count:
{
"aps" : {
"alert" : "You got notificaiton.",
"badge" : 5
}
}
When this payload is received the badge count updates to 5.
Update: As mentioned in the Twilio documentation:
To update badge count on an application icon, you should pass badge count from the Chat Client delegate to the application:
func chatClient(_ client: TwilioChatClient, notificationUpdatedBadgeCount badgeCount: UInt) {
UIApplication.shared.applicationIconBadgeNumber = Int(badgeCount)
}
Note: But, this only works when the App is active. To update the badge count when the App is inactive you need to configure notification payload to the above-mentioned format from via a custom Twilio server, default configuration doesn't allow this.
When the app is inactive you can use this method to append the badge count:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
if UIApplication.shared.applicationState != .active {
UIApplication.shared.applicationIconBadgeNumber += 1
}
}