diff options
Diffstat (limited to 'Juick')
-rw-r--r-- | Juick/AppDelegate.m | 46 |
1 files changed, 25 insertions, 21 deletions
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 { |