Aluminum
Aluminum

Reputation: 2992

How to show an UIAlertView (Or UIView) at the first launch of an Application?

I would like to know how to show an UIAlertView or a UIView ONLY at the first launch of my application.

Thanks.

Upvotes: 2

Views: 1078

Answers (1)

Sam Ritchie
Sam Ritchie

Reputation: 11038

Use NSUserDefaults to store a BOOL, like so:

-(void) showFirstRunAlerts {

    BOOL ranBefore = [[NSUserDefaults standardUserDefaults] boolForKey:@"RanBefore"];

    if (!ranBefore) {
        UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:@"Message title."
                          message:@"Your message."
                          delegate:self
                          cancelButtonTitle:@"Thanks!"
                          otherButtonTitles:nil];
        [alert show];
        [alert release];

        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"RanBefore"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
}

Upvotes: 8

Related Questions