title: How to control when to prompt user for push notification permissions in iOS
body: <p>I've built an application for iPhone using Swift and Xcode 6, and the Parse framework to handle services.</p>
  
  <p>While following the Parse tutorials on how to set up push notifications, the instructions advised that I put the push notifications in the App Delegate file.</p>
  
  <p>This is the code that I have added to the App Delegate file...</p>
  
  <pre><code>@UIApplicationMain
  class AppDelegate: UIResponder, UIApplicationDelegate {
  
      var window: UIWindow?
      var pushNotificationsController: PushNotificationController?
  
  
      func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -&gt; Bool {
  
           // Register for Push Notifications
          self.pushNotificationsController = PushNotificationController()
  
          if application.respondsToSelector("registerUserNotificationSettings:") {
              println("registerUserNotificationSettings.RegisterForRemoteNotificatios")
              let userNotificationTypes: UIUserNotificationType = (.Alert | .Badge | .Sound)
              let settings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil)
              application.registerUserNotificationSettings(settings)
              application.registerForRemoteNotifications()
          }
  
          return true;
      }
  
      func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
          println("didRegisterForRemoteNotificationsWithDeviceToken")
          let installation = PFInstallation.currentInstallation()
          installation.setDeviceTokenFromData(deviceToken)
          installation.saveInBackground()
      }
  }
  </code></pre>
  
  <p>So what happens is that as soon as the application is launched for the first time, the user is prompted to grant these permissions.</p>
  
  <p>What I want to do, is only prompt for these permissions after a certain action has taken place (ie, during a walkthrough of the features of the app) so I can provide a little more context on why we would want them to allow push notifications. </p>
  
  <p>Is it as simple as just copying the below code in the relevant ViewController where I will be expecting to prompt the user?</p>
  
  <pre><code>// In 'MainViewController.swift' file
  
  func promptUserToRegisterPushNotifications() {
          // Register for Push Notifications
          self.pushNotificationsController = PushNotificationController()
  
          if application.respondsToSelector("registerUserNotificationSettings:") {
              println("registerUserNotificationSettings.RegisterForRemoteNotificatios")
              let userNotificationTypes: UIUserNotificationType = (.Alert | .Badge | .Sound)
              let settings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil)
              application.registerUserNotificationSettings(settings)
              application.registerForRemoteNotifications()
          }
  }
  
  func application(application: UIApplication,    didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
          println("didRegisterForRemoteNotificationsWithDeviceToken")
          let installation = PFInstallation.currentInstallation()
          installation.setDeviceTokenFromData(deviceToken)
          installation.saveInBackground()
  }
  </code></pre>
  
  <p>thanks!</p>