Procházet zdrojové kódy

clear code for push notification

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana před 1 rokem
rodič
revize
8d251ff130

+ 1 - 1
ExternalResources/NCApplicationHandle.swift

@@ -32,7 +32,7 @@ class NCApplicationHandle: NSObject {
 
 
     // class: AppDelegate
     // class: AppDelegate
     // func nextcloudPushNotificationAction(data: [String: AnyObject])
     // func nextcloudPushNotificationAction(data: [String: AnyObject])
-    func nextcloudPushNotificationAction(data: [String: AnyObject]) {
+    func nextcloudPushNotificationAction(data: [String: AnyObject], background: Bool) {
     }
     }
     
     
     // class: AppDelegate
     // class: AppDelegate

+ 9 - 3
iOSClient/AppDelegate.swift

@@ -202,7 +202,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         // Push Notification
         // Push Notification
         if let pref = UserDefaults.init(suiteName: NCBrandOptions.shared.capabilitiesGroups),
         if let pref = UserDefaults.init(suiteName: NCBrandOptions.shared.capabilitiesGroups),
            let data = pref.object(forKey: "NOTIFICATION_DATA") as? [String: AnyObject] {
            let data = pref.object(forKey: "NOTIFICATION_DATA") as? [String: AnyObject] {
-            nextcloudPushNotificationAction(data: data)
+            nextcloudPushNotificationAction(data: data, backgound: true)
             pref.set(nil, forKey: "NOTIFICATION_DATA")
             pref.set(nil, forKey: "NOTIFICATION_DATA")
         }
         }
 
 
@@ -409,6 +409,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     // MARK: - Push Notifications
     // MARK: - Push Notifications
 
 
     func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
     func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
+        // push notification in foreground
+        if let pref = UserDefaults.init(suiteName: NCBrandOptions.shared.capabilitiesGroups),
+           let data = pref.object(forKey: "NOTIFICATION_DATA") as? [String: AnyObject] {
+            nextcloudPushNotificationAction(data: data, backgound: false)
+            pref.set(nil, forKey: "NOTIFICATION_DATA")
+        }
         completionHandler([.list, .banner, .sound])
         completionHandler([.list, .banner, .sound])
     }
     }
 
 
@@ -430,8 +436,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         }
         }
     }
     }
 
 
-    func nextcloudPushNotificationAction(data: [String: AnyObject]) {
-        NCApplicationHandle().nextcloudPushNotificationAction(data: data)
+    func nextcloudPushNotificationAction(data: [String: AnyObject], backgound: Bool) {
+        NCApplicationHandle().nextcloudPushNotificationAction(data: data, backgroud: backgound)
     }
     }
 
 
     // MARK: - Login & checkErrorNetworking
     // MARK: - Login & checkErrorNetworking