You can call the API ‘getNotificationCountFromRemote:’ which tells you how many unread messages you have at any given moment. You can invoke that for badging from any number of places.
For more details on badge notifications, please see our developer documentation for iOS.