Jelajahi Sumber

Update push Notification - DELETE

marinofaggiana 5 tahun lalu
induk
melakukan
e3aacf814f
2 mengubah file dengan 12 tambahan dan 1 penghapusan
  1. 6 1
      iOSClient/AppDelegate.m
  2. 6 0
      iOSClient/Networking/OCNetworking.m

+ 6 - 1
iOSClient/AppDelegate.m

@@ -543,6 +543,7 @@ PKPushRegistry *pushRegistry;
                     NSString *subject = [json objectForKey:@"subject"];
                     NSInteger notificationId = [[json objectForKey:@"nid"] integerValue];
                     BOOL delete = [[json objectForKey:@"delete"] boolValue];
+                    BOOL deleteAll = [[json objectForKey:@"delete-all"] boolValue];
 
                     if (!delete && subject) {
                         
@@ -573,7 +574,11 @@ PKPushRegistry *pushRegistry;
                     
                         [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:nil];
                         
-                    } else if (delete) {
+                    } else if (delete || deleteAll) {
+                        
+                        if (deleteAll) {
+                            notificationId = 0;
+                        }
                         
                         [[OCNetworking sharedManager] deletingServerNotification:result.url notificationId:notificationId completion:^(NSString *message, NSInteger errorCode) {
                             NSLog(@"Deleting Server Notification error: %ld", errorCode);

+ 6 - 0
iOSClient/Networking/OCNetworking.m

@@ -2111,8 +2111,14 @@
 
 - (void)deletingServerNotification:(NSString *)serverUrl notificationId:(NSInteger)notificationId completion:(void(^)(NSString *message, NSInteger errorCode))completion
 {
+    // Delete
     NSString *URLString = [NSString stringWithFormat:@"%@/ocs/v2.php/apps/notifications/api/v2/notifications/%ld", serverUrl, (long)notificationId];
     
+    // Delete-all
+    if (notificationId == 0) {
+        URLString = [NSString stringWithFormat:@"%@/ocs/v2.php/apps/notifications/api/v2/notifications", serverUrl];
+    }
+    
     NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:URLString] cachePolicy:0 timeoutInterval:20.0];
     [request addValue:[CCUtility getUserAgent] forHTTPHeaderField:@"User-Agent"];
     [request addValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];