Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ask notifications permissions if denied?

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.

like image 698
Hen Shabat Avatar asked Feb 14 '18 21:02

Hen Shabat


2 Answers

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)
}
like image 135
Rashwan L Avatar answered Nov 13 '22 14:11

Rashwan L


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.

like image 36
valosip Avatar answered Nov 13 '22 16:11

valosip