4

I'm using the following code to request push and local notification permission:

let application = UIApplication.shared
let settings: UIUserNotificationSettings = UIUserNotificationSettings( types:  [.alert, .badge, .sound], categories: nil )

application.registerUserNotificationSettings( settings )
application.registerForRemoteNotifications()

I need to wait for the user to either accept or decline the notifications before I take an action. How can I achieve this?

MVZ
  • 2,220
  • 5
  • 27
  • 57

2 Answers2

4

Note: Apple has since deprecated the answer I've given below. Please see @ergunkocak's answer

When the user has either granted or denied permissions, the callback method in the app delegate is application(_:didRegister:) which is the method you should use for taking specific actions based on the user's chosen permission settings. I suggest reading the documentation here.

Aaron
  • 6,466
  • 7
  • 37
  • 75
3

Swift 3 in AppDelegate.swift :

func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) {
    // Check here
}
ergunkocak
  • 3,334
  • 1
  • 32
  • 31