marinofaggiana 6 年之前
父节点
当前提交
9092c9c69a
共有 3 个文件被更改,包括 45 次插入1 次删除
  1. 11 0
      iOSClient/AppDelegate.m
  2. 2 1
      iOSClient/Networking/OCNetworking.h
  3. 32 0
      iOSClient/Networking/OCNetworking.m

+ 11 - 0
iOSClient/AppDelegate.m

@@ -464,6 +464,7 @@
 {
     NSLog(@"Push notification: %@", userInfo);
     
+    NSUInteger fetchResult = UIBackgroundFetchResultNoData;
     NSString *message = [userInfo objectForKey:@"subject"];
     
     if (message) {
@@ -479,18 +480,25 @@
                     
                     NSString *app = [json objectForKey:@"app"];
                     NSString *subject = [json objectForKey:@"subject"];
+                    NSInteger notificationId = [[json objectForKey:@"nid"] integerValue];
                     
                     if ([app isEqualToString:@"spreed"]) {
                         content.title = @"Nextcloud Talk";
                     } else {
                         content.title = app.capitalizedString;
                     }
+                    content.title = [NSString stringWithFormat:@"%@ (%@)", content.title, result.account];
+                    
                     if (subject) {
                         content.body = subject;
                     } else {
                         content.body = @"Nextcloud notification";
                     }
                     
+                    [[OCNetworking sharedManager] getServerNotification:result.url notificationId:notificationId completion:^(NSString *message, NSInteger errorCode) {
+                        //
+                    }];
+                    
                     content.sound = [UNNotificationSound defaultSound];
                     
                     NSString *identifier = [NSString stringWithFormat:@"Notification-%@", [NSDate new]];
@@ -500,11 +508,14 @@
                     
                     [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:nil];
                     
+                    fetchResult = UIBackgroundFetchResultNewData;
                     break;
                 }
             }
         }
     }
+    
+    completionHandler(fetchResult);
 }
 
 #pragma FIREBASE

+ 2 - 1
iOSClient/Networking/OCNetworking.h

@@ -26,7 +26,7 @@
 #import "AFURLSessionManager.h"
 #import "CCNetworking.h"
 
-@interface OCNetworking : NSObject <NSURLSessionDelegate>
+@interface OCNetworking : NSObject <NSURLSessionDelegate, NSURLSessionTaskDelegate>
 
 + (OCNetworking *)sharedManager;
 
@@ -89,6 +89,7 @@
 
 - (void)subscribingPushNotificationWithAccount:(NSString *)account url:(NSString *)url pushToken:(NSString *)pushToken Hash:(NSString *)pushTokenHash devicePublicKey:(NSString *)devicePublicKey completion:(void(^)(NSString *account, NSString *deviceIdentifier, NSString *deviceIdentifierSignature, NSString *publicKey, NSString *message, NSInteger errorCode))completion;
 - (void)unsubscribingPushNotificationWithAccount:(NSString *)account url:(NSString *)url deviceIdentifier:(NSString *)deviceIdentifier deviceIdentifierSignature:(NSString *)deviceIdentifierSignature publicKey:(NSString *)publicKey completion:(void (^)(NSString *account ,NSString *message, NSInteger errorCode))completion;
+- (void)getServerNotification:(NSString *)serverUrl notificationId:(NSInteger)notificationId completion:(void(^)(NSString *message, NSInteger errorCode))completion;
 
 #pragma mark ===== Manage Mobile Editor OCS API =====
 

+ 32 - 0
iOSClient/Networking/OCNetworking.m

@@ -1690,6 +1690,28 @@
     }];
 }
 
+- (void)getServerNotification:(NSString *)serverUrl notificationId:(NSInteger)notificationId completion:(void(^)(NSString *message, NSInteger errorCode))completion
+{
+    NSString *URLString = [NSString stringWithFormat:@"%@/ocs/v2.php/apps/notifications/api/v2/notifications/%ld", serverUrl, (long)notificationId];
+
+    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"];
+
+    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
+    NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
+
+    NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler: ^(NSData *data, NSURLResponse *response, NSError *error) {
+
+        //NSDictionary *notification = [[response objectForKey:@"ocs"] objectForKey:@"data"];
+        
+        completion(@"", 0);
+        
+    }];
+    
+    [task resume];
+}
+
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== Manage Mobile Editor OCS API =====
 #pragma --------------------------------------------------------------------------------------------
@@ -1940,6 +1962,16 @@
     }];
 }
 
+-(void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler
+{
+    // The pinnning check
+    if ([[CCCertificate sharedManager] checkTrustedChallenge:challenge]) {
+        completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
+    } else {
+        completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil);
+    }
+}
+
 @end
 
 #pragma --------------------------------------------------------------------------------------------