Requesting Unread Card Count

News Feed Badge Example

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 which 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

Badge Example

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 off 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

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];

For more information see the Appboy.h header file. The Stopwatch sample application also has a sample implementation of a badge in FeedAndFeedbackUIViewController.m, as well as code clearing the badge count in AppDelegate.m.

WAS THIS PAGE HELPFUL?