From 2e132e6bbffac6a50b088fb6414c6bfa2a7743ac Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 24 Mar 2019 13:05:27 +0300 Subject: Update badge on discussions tab --- Juick/AppDelegate.m | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'Juick/AppDelegate.m') diff --git a/Juick/AppDelegate.m b/Juick/AppDelegate.m index 802bbab..d33a0fb 100644 --- a/Juick/AppDelegate.m +++ b/Juick/AppDelegate.m @@ -17,6 +17,8 @@ #import "NewPostViewController.h" #import "FeedViewController.h" +NSString * const UserUpdatedNotificationName = @"UserUpdated"; + @interface AppDelegate() -(void) parseNotificationPayload:(NSDictionary *)userInfo; @end @@ -108,7 +110,17 @@ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { if (userInfo[@"service"]) { - application.applicationIconBadgeNumber = [userInfo[@"user"][@"unreadCount"] integerValue]; + User *user = [User fromJSON:userInfo[@"user"]]; + application.applicationIconBadgeNumber = user.unreadCount; + UITabBarController *main = (UITabBarController *)self.window.rootViewController; + UINavigationController *discussions = [main.viewControllers objectAtIndex:1]; + if (user.unreadCount > 0) { + [discussions tabBarItem].badgeColor = [UIColor colorNamed:@"Funny"]; + [discussions tabBarItem].badgeValue = [NSString stringWithFormat:@"%ld", user.unreadCount]; + } else { + [discussions tabBarItem].badgeValue = @""; + } + [[NSNotificationCenter defaultCenter] postNotificationName:UserUpdatedNotificationName object:user]; [[UNUserNotificationCenter currentNotificationCenter] getDeliveredNotificationsWithCompletionHandler:^(NSArray * _Nonnull notifications) { for (UNNotification* notification in notifications) { if ([notification.request.content.userInfo[@"mid"] integerValue] == [userInfo[@"mid"] integerValue]) { -- cgit v1.2.3