I am in the process of evaluating Swift 6 and I noticed that when using the completion handler version of the requestAuthorization
the application crashes with EXC_BAD_INSTRUCTION
exception.
Using this code:
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .sound, .badge]) { success, error in
print(success)
}
Crashes when the project is build with Swift 6 and works normalising when build with Swift 5.
The only solution that I have found so far is to switch to using the async version of that API:
Task {
let center = UNUserNotificationCenter.current()
do {
if try await center.requestAuthorization(options: [.alert, .sound, .badge]) == true {
print("success")
} else {
print("fail")
}
} catch {
print("Error")
}
}
Is the a known issue?
I have submitted feedback with ID "FB15294185".
I will add my initial solution as a comment so it can be marked as solution to the question.
The only solution that I have found so far is to switch to using the async version of the requestAuthorization
API:
Task {
let center = UNUserNotificationCenter.current()
do {
if try await center.requestAuthorization(options: [.alert, .sound, .badge]) == true {
print("success")
} else {
print("fail")
}
} catch {
print("Error")
}
}