I want ask permission in the second time in my home controller, can I do it programmatically?
I mean that the user disable it in the first time and I want to allow him another option to get notification.
You´re not allowed to do that. The notification popup will prompt the first time the user opens the application. What you can do is check if the user hasn´t allowed this. Then you could open the settings page (which basically is what you can do in this case):
let isRegisteredForRemoteNotifications = UIApplication.shared.isRegisteredForRemoteNotifications
if !isRegisteredForRemoteNotifications {
UIApplication.shared.open(URL(string: UIApplicationOpenSettingsURLString)!, options: [:], completionHandler: nil)
}
Swift 5.x
let isRegisteredForRemoteNotifications = UIApplication.shared.isRegisteredForRemoteNotifications
if !isRegisteredForRemoteNotifications {
UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!, options: [:], completionHandler: nil)
}
This is actually not possible. You only get one shot to prompt them for permissions. This is why most apps will present a custom view to explain why a certain permission is needed. And if the user clicks "yes", then they launch the actual permission alert. If they have already declined the permission, you'll need to check if app has certain permission and prompt them to go into settings to activate what is needed.
Here's an example of how you can check if they have given permission.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With