Search code examples
iosapple-push-notificationsquickbloxbadge

How to manage badge counter for push notification from QuickBlox?


I'm using QuickBlox iOS SDK to have chat functionality into my app. It works great. Now there's a requirement from client to manage badge counter for each of the push notifications.

There's some scenarios which may help you to suggest me the flow to handle badge counter:

  1. Currently, a user will get a push when a new 1-1 chat dialog created.
  2. When the users of dialog will do chat to each other they will get push if they're offline.
  3. If any of the user will delete a dialog then other user will get to know about this. And may also delete if he wants and that notification will be send to other user as well.
  4. If user read particular dialog message then it should decrease 1 from badge.
  5. If I send a notification from code then how I can know which number to pass in badge key?

So in 1st and 3rd cases, push notifications will send from the code it self. And 2nd approach will get done by the QuickBlox server for the user who's currently offline. How to handle 4th and 5th cases too.

Please let me suggest the correct approach to handle badge counting for these cases.


Solution

  • At the moment in order to know all unread messages number you need to request dialogs

    + (QBRequest *)dialogsForPage:(QBResponsePage *)page extendedRequest:(NSDictionary *)extendedRequest
                     successBlock:(void(^)(QBResponse *response, NSArray *dialogObjects, NSSet *dialogsUsersIDs, QBResponsePage *page))successBlock
                       errorBlock:(QBRequestErrorBlock)errorBlock
    

    And for all dialogs count unread_messages_count

    In future releases we are planing to add a method such as

    [QBRequest unreadMessagesCount:successBlock:errorBlock]

    Will it be suitable for your purposes?