[SOLVED] Need help with setting default bools

Discussion in 'iOS Programming' started by CitricThunder, Mar 29, 2014.

  1. CitricThunder, Mar 29, 2014
    Last edited: Mar 29, 2014

    CitricThunder macrumors newbie

    Joined:
    Feb 26, 2014
    #1
    I'm trying to make my app detect when it is the first launch and whether or not a UIAlertView will popup again.

    Code:
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        BOOL firstBoot = [[NSUserDefaults standardUserDefaults] boolForKey:@"firstBoot"];
        BOOL showAgain = [[NSUserDefaults standardUserDefaults] boolForKey:@"showAgain"];
        if ((firstBoot) || (showAgain))
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Check the 'About' tab for help!"
                                                        message:@""
                                                       delegate:self
                                              cancelButtonTitle:@"Don't show again"
                                              otherButtonTitles:@"OK", nil];
            [alert show];
            
            [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"firstBoot"];
            [[NSUserDefaults standardUserDefaults] synchronize];
        }
    }
    
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
        if (buttonIndex == [alertView cancelButtonIndex]) {
            [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"showAgain"];
            [[NSUserDefaults standardUserDefaults] synchronize];
        }
    }
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        NSDictionary *defaultUserDefaults = @{ @"firstBoot" : @YES, @"showAgain" : @YES };
        [[NSUserDefaults standardUserDefaults] registerDefaults:defaultUserDefaults];
        return YES;
    }
    When the UIAlertView should be popping up, it isn't. Am I doing something wrong here?
     
  2. CitricThunder thread starter macrumors newbie

    Joined:
    Feb 26, 2014
    #2
    Fixed-had to do some fumbling around with my phone and finally got it to work
     

Share This Page