Application Icon Badge Number - imkit/imkit-ios-framework-v3 GitHub Wiki

We provide numberOfUnreadMessages which you may need on application icon badge number.

IMKit.numberOfUnreadMessages

This varible gives you the number of unread message based on local data. so if you want to get correct number of unread messages without, please call IMRoomsManager.shared.fetchUnsyncRoomsFromServer to synchronize local data to remote server before using IMKit.numberOfUnreadMessages

Recommend put following code at AppDelegate, then the app icon will show badge number. Also you can mix badge number with your other business logic.

func applicationWillResignActive(_ application: UIApplication) {
    application.applicationIconBadgeNumber = IMKit.numberOfUnreadMessages
    // application.applicationIconBadgeNumber = IMKit.numberOfUnreadMessages + otherVariable
}

Listen to changes of number of unread messages

NotificationCenter.default.addObserver(forName: .NumberOfUnreadMessagesDidChange, object: nil, queue: nil) { _ in
    print(IMKit.numberOfUnreadMessages)
}