From eae2af6b5cbb480679e188cc385fc6922194e8ee Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 14 Nov 2018 19:29:43 +0300 Subject: Queue notification processing on main thread and token registration on background one --- Juick/AppDelegate.m | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) (limited to 'Juick/AppDelegate.m') diff --git a/Juick/AppDelegate.m b/Juick/AppDelegate.m index a4932b6..2592b89 100644 --- a/Juick/AppDelegate.m +++ b/Juick/AppDelegate.m @@ -60,15 +60,17 @@ -(void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { NSString *token = [[deviceToken description] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"<>"]]; token = [token stringByReplacingOccurrencesOfString:@" " withString:@""]; - DeviceRegistration *registration = [DeviceRegistration new]; - registration.type = @"apns"; - registration.token = token; - AFHTTPSessionManager *manager = [APIClient sharedClient].manager; - [manager PUT:@"/notifications" parameters:[@[registration] yy_modelToJSONObject] success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { - NSLog(@"success"); - } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { - NSLog(@"fail %@", [error localizedDescription]); - } ]; + [[NSOperationQueue new] addOperationWithBlock:^{ + DeviceRegistration *registration = [DeviceRegistration new]; + registration.type = @"apns"; + registration.token = token; + AFHTTPSessionManager *manager = [APIClient sharedClient].manager; + [manager PUT:@"/notifications" parameters:[@[registration] yy_modelToJSONObject] success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { + NSLog(@"success"); + } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { + NSLog(@"fail %@", [error localizedDescription]); + } ]; + }]; } -(void) application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { @@ -84,18 +86,20 @@ -(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler{ NSDictionary *userInfo = response.notification.request.content.userInfo; [self parseNotificationPayload:userInfo]; - UITabBarController *main = (UITabBarController *)self.window.rootViewController; - if ([self.pushedThread integerValue] > 0) { - [main setSelectedIndex:0]; - UINavigationController *discover = (UINavigationController *)[main.viewControllers objectAtIndex:0]; - [discover popToRootViewControllerAnimated:NO]; - [[discover.viewControllers objectAtIndex:0] performSegueWithIdentifier:@"threadViewSegue" sender:discover]; - } else { - [main setSelectedIndex:1]; - UINavigationController *dialogs = (UINavigationController *)[main.viewControllers objectAtIndex:1]; - [[dialogs.viewControllers objectAtIndex:0] performSegueWithIdentifier:@"chatSegue" sender:dialogs]; - } - completionHandler(); + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + UITabBarController *main = (UITabBarController *)self.window.rootViewController; + if ([self.pushedThread integerValue] > 0) { + [main setSelectedIndex:0]; + UINavigationController *discover = (UINavigationController *)[main.viewControllers objectAtIndex:0]; + [discover popToRootViewControllerAnimated:NO]; + [[discover.viewControllers objectAtIndex:0] performSegueWithIdentifier:@"threadViewSegue" sender:discover]; + } else { + [main setSelectedIndex:1]; + UINavigationController *dialogs = (UINavigationController *)[main.viewControllers objectAtIndex:1]; + [[dialogs.viewControllers objectAtIndex:0] performSegueWithIdentifier:@"chatSegue" sender:dialogs]; + } + completionHandler(); + }]; } -(void) parseNotificationPayload:(NSDictionary *)userInfo { -- cgit v1.2.3