From 6f8f700ea02102621e88da6a6f96a869cdeefb7b Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 20 Mar 2021 05:37:56 +0300 Subject: Fix The Bug No. 1 * do not run network requests when app is not active * handle situation when viewDidLoad happens before app is active --- Juick/AppDelegate.m | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'Juick/AppDelegate.m') diff --git a/Juick/AppDelegate.m b/Juick/AppDelegate.m index bfde8cf..aac90c7 100644 --- a/Juick/AppDelegate.m +++ b/Juick/AppDelegate.m @@ -16,8 +16,6 @@ #import "FeedViewController.h" #import "NSData+Hex.h" -NSString * const UserUpdatedNotificationName = @"UserUpdated"; - @interface AppDelegate() -(void) parseNotificationPayload:(NSDictionary *)userInfo; @end @@ -119,24 +117,17 @@ NSString * const UserUpdatedNotificationName = @"UserUpdated"; if (userInfo[@"service"]) { User *user = [User fromJSON:userInfo[@"user"]]; application.applicationIconBadgeNumber = user.unreadCount; - UITabBarController *main = (UITabBarController *)[self navigator]; - UIViewController *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 = nil; - } - [[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]) { [[UNUserNotificationCenter currentNotificationCenter] removeDeliveredNotificationsWithIdentifiers:@[notification.request.identifier]]; } } + completionHandler(UIBackgroundFetchResultNewData); }]; + } else { + completionHandler(UIBackgroundFetchResultNoData); } - completionHandler(UIBackgroundFetchResultNewData); } -(void) parseNotificationPayload:(NSDictionary *)userInfo { -- cgit v1.2.3