Marino Faggiana преди 6 години
родител
ревизия
73b34325fe
променени са 2 файла, в които са добавени 17 реда и са изтрити 5 реда
  1. 14 4
      Notification Service Extension/NotificationService.swift
  2. 3 1
      iOSClient/AppDelegate.m

+ 14 - 4
Notification Service Extension/NotificationService.swift

@@ -25,6 +25,7 @@ import UserNotifications
 
 class NotificationService: UNNotificationServiceExtension {
 
+    let privateKey = CCUtility.getPushNotificationPrivateKey()
     var contentHandler: ((UNNotificationContent) -> Void)?
     var bestAttemptContent: UNMutableNotificationContent?
 
@@ -36,19 +37,25 @@ class NotificationService: UNNotificationServiceExtension {
         if let bestAttemptContent = bestAttemptContent {
             
             bestAttemptContent.title = "Nextcloud notification 🔔"
-            bestAttemptContent.body = ""
+            bestAttemptContent.body = "Nextcloud notification 🔔"
             
             let message = bestAttemptContent.userInfo["subject"] as! String
             
-            guard let decryptedMessage = NCPushNotificationEncryption.sharedInstance().decryptPushNotification(message, withDevicePrivateKey: CCUtility.getPushNotificationPrivateKey()) else {
-                
+            guard let privateKey = CCUtility.getPushNotificationPrivateKey() else {
                 contentHandler(bestAttemptContent)
                 return
             }
             
+            guard let decryptedMessage = NCPushNotificationEncryption.sharedInstance().decryptPushNotification(message, withDevicePrivateKey: privateKey) else {
+                contentHandler(bestAttemptContent)
+                return
+            }
+            
+            NSLog("[LOG] PN Decr Message, %@", decryptedMessage)
+            
             let pushNotification = NCPushNotification.init(fromDecryptedString: decryptedMessage)
             if (pushNotification != nil) {
-                bestAttemptContent.title = ""
+                bestAttemptContent.title = "Nextcloud notification 🔔"
                 bestAttemptContent.body = pushNotification!.bodyForRemoteAlerts()
             }
             
@@ -60,8 +67,11 @@ class NotificationService: UNNotificationServiceExtension {
         // Called just before the extension will be terminated by the system.
         // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
         if let contentHandler = contentHandler, let bestAttemptContent =  bestAttemptContent {
+            NSLog("[LOG] PN X1")
             contentHandler(bestAttemptContent)
         }
+        
+        NSLog("[LOG] PN X2")
     }
 
 }

+ 3 - 1
iOSClient/AppDelegate.m

@@ -432,7 +432,9 @@
     NSString *message = [response.notification.request.content.userInfo objectForKey:@"subject"];
     
     if (message && [NCPushNotificationEncryption sharedInstance].ncPNPrivateKey) {
-        NSString *decryptedMessage = [[NCPushNotificationEncryption sharedInstance] decryptPushNotification:message withDevicePrivateKey:[NCPushNotificationEncryption sharedInstance].ncPNPrivateKey];
+        
+        NSData *privateKey = [CCUtility getPushNotificationPrivateKey];
+        NSString *decryptedMessage = [[NCPushNotificationEncryption sharedInstance] decryptPushNotification:message withDevicePrivateKey:privateKey];
         if (decryptedMessage) {
            
             NCPushNotification *pushNotification = [NCPushNotification pushNotificationFromDecryptedString:decryptedMessage];