소스 검색

Merge pull request #1119 from deltachat/move-more-to-bg

more more to bg-thread
cyBerta 4 년 전
부모
커밋
8ea7587ae6
1개의 변경된 파일16개의 추가작업 그리고 14개의 파일을 삭제
  1. 16 14
      deltachat-ios/Helper/NotificationManager.swift

+ 16 - 14
deltachat-ios/Helper/NotificationManager.swift

@@ -28,20 +28,20 @@ public class NotificationManager {
             forName: dcNotificationIncoming,
             object: nil, queue: OperationQueue.main
         ) { notification in
-            if let ui = notification.userInfo,
-               let chatId = ui["chat_id"] as? Int,
-               let messageId = ui["message_id"] as? Int,
-               !UserDefaults.standard.bool(forKey: "notifications_disabled") {
-                let array = DcContext.shared.getFreshMessages()
-                UIApplication.shared.applicationIconBadgeNumber = array.count
-                NotificationManager.updateApplicationIconBadge(reset: false)
+            DispatchQueue.global(qos: .background).async {
+                if let ui = notification.userInfo,
+                   let chatId = ui["chat_id"] as? Int,
+                   let messageId = ui["message_id"] as? Int,
+                   !UserDefaults.standard.bool(forKey: "notifications_disabled") {
+                    let array = DcContext.shared.getFreshMessages()
+                    UIApplication.shared.applicationIconBadgeNumber = array.count
+                    NotificationManager.updateApplicationIconBadge(reset: false)
 
-                let chat = DcContext.shared.getChat(chatId: chatId)
-                if chat.isMuted {
-                    return
-                }
+                    let chat = DcContext.shared.getChat(chatId: chatId)
+                    if chat.isMuted {
+                        return
+                    }
 
-                DispatchQueue.global(qos: .background).async {
                     let content = UNMutableNotificationContent()
                     let msg = DcMsg(id: messageId)
                     content.title = chat.isGroup ? chat.name : msg.getSenderName(msg.fromContact)
@@ -81,8 +81,10 @@ public class NotificationManager {
             forName: dcNotificationIncoming,
             object: nil, queue: OperationQueue.main
         ) { _ in
-            if !UserDefaults.standard.bool(forKey: "notifications_disabled") {
-                NotificationManager.updateApplicationIconBadge(reset: false)
+            DispatchQueue.global(qos: .background).async {
+                if !UserDefaults.standard.bool(forKey: "notifications_disabled") {
+                    NotificationManager.updateApplicationIconBadge(reset: false)
+                }
             }
         }
     }