title: Push notifications and token device in Swift
body: <p>I am working on an App that need to know the device token to send notification to the users when they give their authorization.
  The first time the system ask the authorization for notification. If user say "allow" the system calls for me the method didRegisterForRemoteNotificationsWithDeviceToken and in the body of this method I write in UserDefaults the device token.
  This is the flow:
  1) System ask for permission
  2) in didFinishLaunchingWithOptions (inside AppDelegate) I call this method in my class that manage the Notification Framework:</p>
  
  <pre><code>   func registerForPushNotifications() {
          UNUserNotificationCenter.current().delegate = self
          UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) {
              (granted, error) in
              print("NFM permission granted: \(granted)")
              // 1. Check if permission granted
              guard granted else { return }
              // 2. Attempt registration for remote notifications on the main thread
              DispatchQueue.main.async {
                  UIApplication.shared.registerForRemoteNotifications()
              }
          }
      }
  </code></pre>
  
  <p>3) the system calls for me the method didRegisterForRemoteNotificationsWithDeviceToken (in AppDelegate) and everything works fine.
  In the body of the method I write the token UserDefaults settings.
  The second case happen when the user denied the permission the first time.
  In this second case in another ViewController of my app I check if the user has given permission for push notification using the device setting (so out of the app). In a specific section of my app I use this method to verify if the user has given the authorization (the is always in my class that manage the Notification Framework).</p>
  
  <pre><code>    func checkPremissionStatus() -&gt; Bool{
      var isAuth = false
      UNUserNotificationCenter.current().delegate = self
      UNUserNotificationCenter.current().getNotificationSettings { (settings) in
          print("NFM checkPremissionStatus -&gt; notification status")
          switch settings.authorizationStatus {
          case .authorized:
              print("NFM checkPremissionStatus -&gt; authorized status")
              self.autorizzato = true
              isAuth = true
          //TODO check pending notification...
          case .denied:
              print("NFM checkPremissionStatus -&gt; denied status")
              self.autorizzato = false
              isAuth = false
          case .notDetermined:
              print("NFM notDetermined never see this print")
          }
      }
      return isAuth
  }
  </code></pre>
  
  <p>In this specific case the method didRegisterForRemoteNotificationsWithDeviceToken it is not called and so I cannot store the token. The alert for ask to the user the authorization is showed only the first time that the user use open the app.
  The next times the user open the app the system does not show the alert anymore.
  How can I solve this problem?</p>
  
  <p>Thanks.</p>