Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

CitricThunder

macrumors newbie
Original poster
Feb 26, 2014
8
0
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?
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.