When requesting authorization for local notifications using:
do {
_ = try await current().requestAuthorization(options: [.alert])
} catch let error {
print(error)
}
I always get the error message:
Error Domain=UNErrorDomain Code=1 "Notifications are not allowed for this application" UserInfo={NSLocalizedDescription=Notifications are not allowed for this application}
If I go to
System preferences > Notifications & Focus > My app name
I can see that they are disabled, but I never disabled them myself and I can't find a way to reset the setting.
Using Swift, macOS 12 Monterey, and the updated UserNotifications
API using async/await.
Need to manually remove all traces of your app and try again from scratch, following all the steps listed here:
Applications/
)ā ā§ k
[path to Xcode]/Xcode/DerivedData
[path to Xcode]/Xcode/Products
[path to Xcode]/Xcode/Archives
~/Library/Containers/[my app name]
[my app name].app
After all these steps requesting authorization should work:
do {
_ = try await current().requestAuthorization(options: [.alert])
} catch let error {
print(error)
}
It will only work the first time, if you don't answer the notification or if you don't allow them you will need to repeat all the steps to try once more.