Selaa lähdekoodia

Merge pull request #1122 from deltachat/applicationIconBadgeNumber_mainthread

call ApplicationIconBadgeNumber from mainthread
bjoern 4 vuotta sitten
vanhempi
commit
083126f2aa
1 muutettua tiedostoa jossa 7 lisäystä ja 7 poistoa
  1. 7 7
      deltachat-ios/Helper/NotificationManager.swift

+ 7 - 7
deltachat-ios/Helper/NotificationManager.swift

@@ -10,11 +10,13 @@ public class NotificationManager {
 
 
     public static func updateApplicationIconBadge(reset: Bool) {
-        if reset {
-            UIApplication.shared.applicationIconBadgeNumber = 0
-        } else {
-            let array = DcContext.shared.getFreshMessages()
-            UIApplication.shared.applicationIconBadgeNumber = array.count
+        var unreadMessages = 0
+        if !reset {
+            unreadMessages = DcContext.shared.getFreshMessages().count
+        }
+
+        DispatchQueue.main.async {
+            UIApplication.shared.applicationIconBadgeNumber = unreadMessages
         }
     }
 
@@ -39,8 +41,6 @@ public class NotificationManager {
                         return
                     }
 
-                    let array = DcContext.shared.getFreshMessages()
-                    UIApplication.shared.applicationIconBadgeNumber = array.count
                     NotificationManager.updateApplicationIconBadge(reset: false)
 
                     let chat = DcContext.shared.getChat(chatId: chatId)