I am trying to implement a settings screen in an iOS 11 app, where I need a UISwitch that would be used to control user notifications. When set on off, I want to give up the permissions to notifications, when set to on, I want to request for permissions (standard dialog asking for user permission to send her notifications).
To ask for permission, I found following code:
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound]) { (granted, error) in
// Enable or disable features based on authorization.
}
However, if I turn off notifications for the app in system settings, this code does not pop up a dialog with a request, and it just simply returns false in granted
.
I was not able to find anything on how to give up permissions.
Any hint on how to solve the problem? Is it even possible, or does Apple assume that this task should be left only to system settings?