Explorar o código

remove foreground notifications after 3 seconds

cyberta %!s(int64=4) %!d(string=hai) anos
pai
achega
8335aedf45
Modificáronse 1 ficheiros con 7 adicións e 2 borrados
  1. 7 2
      deltachat-ios/AppDelegate.swift

+ 7 - 2
deltachat-ios/AppDelegate.swift

@@ -278,8 +278,13 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
         completionHandler()
     }
 
-    func userNotificationCenter(_: UNUserNotificationCenter, willPresent _: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
-        logger.info("notifications: forground notification appeared")
+    func userNotificationCenter(_: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
+        //remove foreground notifications after 3 seconds
+        if notification.request.identifier == Constants.notificationIdentifier {
+            DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
+                UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: [notification.request.identifier])
+            }
+        }
         completionHandler([.alert, .sound])
     }