diff options
Diffstat (limited to 'Juick/AppDelegate.m')
-rw-r--r-- | Juick/AppDelegate.m | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/Juick/AppDelegate.m b/Juick/AppDelegate.m index 2592b89..d5d5b9b 100644 --- a/Juick/AppDelegate.m +++ b/Juick/AppDelegate.m @@ -66,7 +66,7 @@ registration.token = token; AFHTTPSessionManager *manager = [APIClient sharedClient].manager; [manager PUT:@"/notifications" parameters:[@[registration] yy_modelToJSONObject] success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { - NSLog(@"success"); + NSLog(@"success %@", token); } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { NSLog(@"fail %@", [error localizedDescription]); } ]; @@ -98,14 +98,27 @@ UINavigationController *dialogs = (UINavigationController *)[main.viewControllers objectAtIndex:1]; [[dialogs.viewControllers objectAtIndex:0] performSegueWithIdentifier:@"chatSegue" sender:dialogs]; } - completionHandler(); }]; + completionHandler(); +} + +- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { + if (userInfo[@"service"]) { + [[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); } -(void) parseNotificationPayload:(NSDictionary *)userInfo { if (userInfo != nil) { - self.pushedThread = [userInfo objectForKey:@"mid"]; - self.pushedUname = [userInfo objectForKey:@"uname"]; + self.pushedThread = userInfo[@"mid"]; + self.pushedUname = userInfo[@"uname"]; } } |