title: NSUserDefaults - displaying a UIAlertView on first launch - button behaviour
body: <p>I am using NSUserDefaults to display a UIAlertView the first time my application is loaded.  The Alert has a Dismiss and a Rate Now button.  The Dismiss is self explanatory and works fine, however, I want the Rate Now button to open up the relevant location within the App Store on the device.  I am using the following code in my AppDelegate.m file.</p>
  
  <pre><code>NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  NSString *alertshown = [defaults stringForKey:@"alertshown"]; {
  if (alertshown == nil) {
  
      UIAlertView *oneTimeWelcome = [[UIAlertView alloc]
                                    initWithTitle: @"Thank You"
                                    message: @"Blah Blah Blah Blah"
                                    delegate: self
                                    cancelButtonTitle:@"Dismiss"
                                    otherButtonTitles:@"Rate Now",nil];
      [oneTimeWelcome show];
      [oneTimeWelcome release];
  
      [defaults setObject:@"alertwasdisplayed" forKey:@"alertshown"];
  }
  </code></pre>
  
  <p>On a previous use of a second button in a UIAlertView I have used this code to call a new view;</p>
  
  <pre><code>- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  {
      if (buttonIndex == 0)
      {
          // Do something wonderful here
      }
      else if (buttonIndex == 1)
      {
          AppSupportView *controller = [[AppSupportView alloc] initWithNibName:@"AppSupportView" bundle:nil];
          controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
          [self presentModalViewController:controller animated:YES];
          [controller release];
  
      }
  </code></pre>
  
  <p>However, this does not work when the code is used in the AppDelegate.m file??  Any examples would be great to get my Rate Now button to open up App Store.  Sorry about the formatting but it wouldnt let me alter the text</p>
  
  <p>EDIT - This is the entirety of the code I am dealing with in the AppDelegate.m file</p>
  
  <p>{ //This following block of code displays a UIAlert when the user first opens the application. This is only displays if alertshown == 0</p>
  
  <pre><code>NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  NSString *alertshown = [defaults stringForKey:@"alertshown"]; {
  if (alertshown == nil) {
  
      UIAlertView *oneTimeWelcome = [[UIAlertView alloc]
                                    initWithTitle: @"Thank You"
                                    message: @"Thanks, please rate blah blah blah"
                                    delegate: self
                                    cancelButtonTitle:@"Dismiss"
                                    otherButtonTitles:@"Rate Now",nil];
      [oneTimeWelcome show];
      [oneTimeWelcome release];
  
      [defaults setObject:@"alertwasdisplayed" forKey:@"alertshown"];
  </code></pre>
  
  <p>}
      }</p>
  
  <pre><code>- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
  
      if (buttonIndex == 0)
      {
          // Yes, do something
      }
      else if (buttonIndex == 1)
      {
  </code></pre>