diff options
author | 2021-03-20 05:37:56 +0300 | |
---|---|---|
committer | 2021-03-20 05:37:56 +0300 | |
commit | 6f8f700ea02102621e88da6a6f96a869cdeefb7b (patch) | |
tree | 555032fdb26d904214db2911c83314d3a53c4547 /Juick/AppDelegate.m | |
parent | 158a5fecc5f3bb56e8f4c0f7b152bff4d19549a4 (diff) |
Fix The Bug No. 1
* do not run network requests when app is not active
* handle situation when viewDidLoad happens before app is active
Diffstat (limited to 'Juick/AppDelegate.m')
-rw-r--r-- | Juick/AppDelegate.m | 15 |
1 files changed, 3 insertions, 12 deletions
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<UNNotification *> * _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 { |