@@ -23,12 +23,13 @@ import UIKit
2323import UserNotifications
2424
2525class NotificationService : UNNotificationServiceExtension {
26-
2726 var contentHandler : ( ( UNNotificationContent ) -> Void ) ?
2827 var bestAttemptContent : UNMutableNotificationContent ?
28+ var request : UNNotificationRequest ?
2929
3030 override func didReceive( _ request: UNNotificationRequest , withContentHandler contentHandler: @escaping ( UNNotificationContent ) -> Void ) {
3131 self . contentHandler = contentHandler
32+ self . request = request
3233 bestAttemptContent = ( request. content. mutableCopy ( ) as? UNMutableNotificationContent )
3334
3435 if let bestAttemptContent = bestAttemptContent {
@@ -37,11 +38,19 @@ class NotificationService: UNNotificationServiceExtension {
3738 do {
3839 if let message = bestAttemptContent. userInfo [ " subject " ] as? String {
3940 for tableAccount in NCManageDatabase . shared. getAllTableAccount ( ) {
40- guard let privateKey = NCKeychain ( ) . getPushNotificationPrivateKey ( account: tableAccount. account) ,
41- let decryptedMessage = NCPushNotificationEncryption . shared ( ) . decryptPushNotification ( message, withDevicePrivateKey: privateKey) ,
42- let data = decryptedMessage. data ( using: . utf8) else {
41+ guard let privateKey = NCKeychain ( ) . getPushNotificationPrivateKey ( account: tableAccount. account) else {
42+ bestAttemptContent. body = " Error retrieving private key for \( tableAccount. account) "
43+ continue
44+ }
45+ guard let decryptedMessage = NCPushNotificationEncryption . shared ( ) . decryptPushNotification ( message, withDevicePrivateKey: privateKey) else {
46+ bestAttemptContent. body = " Error decryption for \( tableAccount. account) "
47+ continue
48+ }
49+ guard let data = decryptedMessage. data ( using: . utf8) else {
50+ bestAttemptContent. body = " Error decryption data utf8 for \( tableAccount. account) "
4351 continue
4452 }
53+
4554 if var json = try JSONSerialization . jsonObject ( with: data) as? [ String : AnyObject ] ,
4655 let subject = json [ " subject " ] as? String {
4756 bestAttemptContent. body = subject
@@ -50,7 +59,10 @@ class NotificationService: UNNotificationServiceExtension {
5059 pref. set ( json, forKey: " NOTIFICATION_DATA " )
5160 pref. synchronize ( )
5261 }
62+ } else {
63+ bestAttemptContent. body = " Error JSON Serialization for \( tableAccount. account) "
5364 }
65+ break
5466 }
5567 }
5668 } catch let error as NSError {
@@ -66,9 +78,8 @@ class NotificationService: UNNotificationServiceExtension {
6678 // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
6779 if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
6880 bestAttemptContent. title = " "
69- bestAttemptContent. body = " Nextcloud notification "
81+ bestAttemptContent. body = " Nextcloud Notification Time Will Expire "
7082 contentHandler ( bestAttemptContent)
7183 }
7284 }
73-
7485}
0 commit comments