AppboyKit (also known as the Objective-C SDK) is no longer supported and has been replaced by the Swift SDK. It will no longer receive new features, bug fixes, security updates, or technical support—however, messaging and analytics will continue to function as normal. To learn more, see Introducing the New Braze Swift SDK.
Badges
News Feed is being deprecated. We recommend migrating to our Content Cards messaging channel instead—it’s more flexible, customizable, and reliable. To get started, check out Migrating from News Feed.
Requesting unread News Feed card counts
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 following method declarations in ABKFeedController
describe this in detail:
1
2
3
4
5
6
7
8
9
10
11
12
- (NSInteger)unreadCardCountForCategories:(ABKCardCategory)categories;
/*
This method returns the number of currently active Content Cards that have not been viewed.
A "view" happens when a card becomes visible in the Content Cards view. This differentiates between cards that 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 Content Cards views or across multiple devices.
*/
- (NSInteger)cardCountForCategories:(ABKCardCategory)categories;
/*
This method returns the total number of currently active Content Cards. Cards are counted only once, even if they appear in multiple Content Cards views.
*/
Displaying the number of unread News Feed items on the app badge count
In addition to serving as push notification reminders for an app, badges can also 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 after the app is closed and the user’s session ends:
1
(void)applicationDidEnterBackground:(UIApplication *)application
1
func applicationDidEnterBackground(_ application: UIApplication)
Within this 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.