summaryrefslogtreecommitdiff
path: root/Juick/AppDelegate.m
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-11-14 19:29:43 +0300
committerGravatar Vitaly Takmazov2018-11-14 19:29:43 +0300
commiteae2af6b5cbb480679e188cc385fc6922194e8ee (patch)
treeaa5d14e2233537e1c3ba8acb0e6e8297397616a8 /Juick/AppDelegate.m
parent40d7419dc846d3afb394c816762f20c8001ae512 (diff)
Queue notification processing on main thread and token registration on background one
Diffstat (limited to 'Juick/AppDelegate.m')
-rw-r--r--Juick/AppDelegate.m46
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 {