Requesting Unread Card Count
Badges are a great way to call attention to new content awaiting your users in the News Feed. If you’d like to add a badge to your News Feed, the Braze SDK provides methods to query the following:
- Unread News Feed Cards for the current user
- Total Viewable News Feed Cards for the current user
The method declarations in ABKFeedController below describe this in detail:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 /*! * This method returns the number of currently active cards that have not been viewed in the given categories. * A "view" happens when a card becomes visible in the feed view. This differentiates * between cards which are off-screen in the scrolling view, and those which * are on-screen; when a card scrolls onto the screen, it's counted as viewed. * * Cards are counted as viewed only once -- if a card scrolls off the screen and * back on, it's not re-counted. * * Cards are counted only once even if they appear in multiple feed views or across multiple devices. */ - (NSInteger)unreadCardCountForCategories:(ABKCardCategory)categories; /*! * This method returns the total number of currently active cards belongs to given categories. Cards are * counted only once even if they appear in multiple feed views. */ - (NSInteger)cardCountForCategories:(ABKCardCategory)categories;
Displaying Number of Unread News Feed Items on App Badge Count
In addition to serving as push notification reminders for an app, badges can also be utilized to denote unviewed items in the user’s News Feed. Updating the badge count based on unread News Feed updates can be a valuable tool in attracting users back to your app and increasing sessions.
Call this method which records the badge count once the app is closed and the user’s session ends.
1 (void)applicationDidEnterBackground:(UIApplication *)application
1 func applicationDidEnterBackground(_ application: UIApplication)
Within the above method, implement the following code which actively updates the badge count while the user views cards during a given session.
1 [UIApplication sharedApplication].applicationIconBadgeNumber = [[Appboy sharedInstance].feedController unreadCardCountForCategories:ABKCardCategoryAll];
1 UIApplication.shared.applicationIconBadgeNumber = Appboy.sharedInstance()?.feedController.unreadCardCount(forCategories: ABKCardCategory.all) ?? 0
At any point, for example in the
applicationDidBecomeActive method, use the following code to clear the badge count.
1 [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
1 UIApplication.shared.applicationIconBadgeNumber = 0
For more information see the
Appboy.h header file.