I've got a function in my code to check if we can have permission to display a UILocalNotification.
open func hasPermission() -> Bool {
if let permissions = UIApplication.shared.currentUserNotificationSettings {
if permissions.types.contains(.alert) {
return true
}
}
return false
}
This code has triggered a warning in Xcode 9:
UI API called from background thread: UIApplication.currentUserNotificationSettings must be used from main thread only
How do I fix this? I know there is the DispatchQueue.main.async
method, just not sure how to implemented that.