Post

Replies

Boosts

Views

Activity

Reply to Calling NUserNotificationCenter getDeliveredNotifications in iOS 11 always returns empty array
I found the solution and now it's working properly.As described here:https://developer.apple.com/documentation/usernotifications/unusernotificationcenter/1649520-getdeliverednotificationsThe completionHandler is executed on background thread and the array of notifications cloud not be ready immediatelly.I used a DispatchSemaphore in order to wait and get the notiification array.let semaphore = DispatchSemaphore(value: 0)let center = UNUserNotificationCenter.current() let customID = data["custom-payload-id"] as? String ?? "-1";center.getDeliveredNotifications { notifications in // background Thread here let matching = notifications.first(where: { notify in let id = userInfo["custom-payload-id"] as? String return id == customID }) if let matchExists = matching { center.removeDeliveredNotifications( withIdentifiers: [matchExists.request.identifier]) } semaphore.signal() }// main thread here semaphore.wait()--T
Jan ’20