瀏覽代碼

remove foreground notifications after 3 seconds

cyberta 4 年之前
父節點
當前提交
8335aedf45
共有 1 個文件被更改,包括 7 次插入2 次删除
  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])
     }