title: Unchecking a switch depending on user decision
body: <p>I'm building an app that asks the user for permission to post notifications when the user enables a switch. I'm using this code:</p>
  
  <pre><code>- (IBAction)mySwitchValueChanged:(id)sender {
  if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){
      [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]]; // ask the user for permission
  }
  
  if ([[UIApplication sharedApplication] respondsToSelector:@selector(currentUserNotificationSettings)]) { // Check it's iOS 8 and above
      UIUserNotificationSettings *grantedSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];
      if (grantedSettings.types != UIUserNotificationTypeNone)
      {
          // Accepted
      } else
      {
          [self.mySwitch setOn:NO]; // Declined
      }
  }
  }
  </code></pre>
  
  <p>The desired behaviour is as follows:</p>
  
  <ul>
  <li>User slides switch</li>
  <li>Alert asks for permission</li>
  <li>Code waits for user to decide</li>
  <li>Either does whatever I code where I've put // accepted, or disables the switch.</li>
  </ul>
  
  <p>The current behaviour makes the code run through at once, and doesn't wait for the user to decide. How can I change this to get the desired behaviour?</p>
  
  <p>Thanks!</p>