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 | |
parent | 99e30a020263d7723d1229b14e0ba3a22ecc81ad (diff) |
Remove read notifications
Diffstat (limited to 'Juick')
-rw-r--r-- | Juick/AppDelegate.m | 21 | ||||
-rw-r--r-- | Juick/Model/Message.h | 1 | ||||
-rw-r--r-- | Juick/Model/Message.m | 3 |
3 files changed, 18 insertions, 7 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"]; } } diff --git a/Juick/Model/Message.h b/Juick/Model/Message.h index 45b14fa..8e1b01a 100644 --- a/Juick/Model/Message.h +++ b/Juick/Model/Message.h @@ -24,5 +24,6 @@ @property NSString *repliesBy; @property NSNumber *repliesCount; @property Attachment *attachment; +@property BOOL service; @end diff --git a/Juick/Model/Message.m b/Juick/Model/Message.m index 2a4090a..d00f705 100644 --- a/Juick/Model/Message.m +++ b/Juick/Model/Message.m @@ -13,9 +13,6 @@ + (NSDictionary *)modelCustomPropertyMapper { return @{@"text" : @"body", - @"mid" : @"mid", - @"rid" : @"rid", - @"entities": @"entities", @"attach" : @"photo.small", @"repliesCount": @"replies", @"repliesBy": @"repliesby"}; |