Browse Source

Improvements

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 1 year ago
parent
commit
e564f60083
2 changed files with 11 additions and 17 deletions
  1. 3 3
      ExternalResources/NCApplicationHandle.swift
  2. 8 14
      iOSClient/AppDelegate.swift

+ 3 - 3
ExternalResources/NCApplicationHandle.swift

@@ -31,10 +31,10 @@ class NCApplicationHandle: NSObject {
     let appDelegate = (UIApplication.shared.delegate as? AppDelegate)!
 
     // class: AppDelegate
-    // func nextcloudPushNotificationAction(data: [String: AnyObject], background: Bool)
-    func nextcloudPushNotificationAction(data: [String: AnyObject], background: Bool) {
+    // func nextcloudPushNotificationAction(data: [String: AnyObject])
+    func nextcloudPushNotificationAction(data: [String: AnyObject]) {
     }
-    
+
     // class: AppDelegate
     // func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void)
     func applicationOpenUserActivity(_ userActivity: NSUserActivity) -> Bool {

+ 8 - 14
iOSClient/AppDelegate.swift

@@ -199,13 +199,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
             NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Initialize Auto upload with \(items) uploads")
         }
 
-        // Push Notification
-        if let pref = UserDefaults.init(suiteName: NCBrandOptions.shared.capabilitiesGroups),
-           let data = pref.object(forKey: "NOTIFICATION_DATA") as? [String: AnyObject] {
-            nextcloudPushNotificationAction(data: data, background: true)
-            pref.set(nil, forKey: "NOTIFICATION_DATA")
-        }
-
         NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterApplicationDidBecomeActive)
     }
 
@@ -409,16 +402,17 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     // MARK: - Push Notifications
 
     func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
-        // push notification in foreground
+        completionHandler([.list, .banner, .sound])
+    }
+
+    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
+
         if let pref = UserDefaults.init(suiteName: NCBrandOptions.shared.capabilitiesGroups),
            let data = pref.object(forKey: "NOTIFICATION_DATA") as? [String: AnyObject] {
-            nextcloudPushNotificationAction(data: data, background: false)
+            nextcloudPushNotificationAction(data: data)
             pref.set(nil, forKey: "NOTIFICATION_DATA")
         }
-        completionHandler([.list, .banner, .sound])
-    }
 
-    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
         completionHandler()
     }
 
@@ -436,8 +430,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         }
     }
 
-    func nextcloudPushNotificationAction(data: [String: AnyObject], background: Bool) {
-        NCApplicationHandle().nextcloudPushNotificationAction(data: data, background: background)
+    func nextcloudPushNotificationAction(data: [String: AnyObject]) {
+        NCApplicationHandle().nextcloudPushNotificationAction(data: data)
     }
 
     // MARK: - Login & checkErrorNetworking