diff options
author | Vitaly Takmazov | 2018-11-30 00:07:45 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-11-30 00:07:45 +0300 |
commit | bff94ce64e6729bda5f1e7f728796f87d138fcbe (patch) | |
tree | 3e903cb3ce7b2bfcad92ffc84a021d534606b2b3 /Juick/AppDelegate.m | |
parent | 99e30a020263d7723d1229b14e0ba3a22ecc81ad (diff) |
Remove read notifications
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"]; } } |