Explorar o código

ensure UIApplication.shared.applicationIconBadgeNumber will be called from the main thread

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

+ 7 - 5
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
         }
     }