sandy
sandy

Reputation: 23

How to Show popup Alert view when apps run first time?

Everyone, I'm working in iphone. I've a problem that I want to show a alert view popup when my apps run first time in iphone. I'm not getting how to do this. Please someone help me.

Upvotes: 0

Views: 2416

Answers (6)

Akshay
Akshay

Reputation: 5765

Save a BOOL value using NSUserDefaults which corresponds to whether it is the application's first launch. If you find the boolean to be YES (or don't find the value), display the alert and set the value to NO.

Upvotes: 0

Tim Kozak
Tim Kozak

Reputation: 4182

3 simple lines

-(BOOL)application:(UIApplication *)application … {
    if(![[[NSUserDefaults standardUserDefaults] objectForKey:@"NOT_FIRST_TIME"] boolValue])
    {
        [[[[UIAlertView alloc] initWithTitle:nil message:@"message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] autorelease] show];
        [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:YES] forKey:@"NOT_FIRST_TIME"];
    }
}

Upvotes: 1

Maximilian Liesegang
Maximilian Liesegang

Reputation: 994

BOOL foo = [[NSUserDefaults standardUserDefaults]boolForKey:@"previouslyLaunched"];
if (!foo) 
{
    NSLog(@"FirstLaunch");
    [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"previouslyLaunched"];
}

Edit: What Akshay said earlier, with some code.

Upvotes: 4

PJR
PJR

Reputation: 13180

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    if([defaults objectForKey:@"FirstTime"] == nil) 
    {
      //your alert message  
    }  
     [defaults setObject:@"firsttime" forKey:@"FirstTime"];

Upvotes: 0

Minakshi
Minakshi

Reputation: 1433

Put the alertview code in didFinishLaunchingWithOptions function in delegate.m

Upvotes: 0

Vlad
Vlad

Reputation: 10780

You will probably need to store some data on first run of the application (like current date). Every time the application starts you will check for this data and if it doesn't exist store it and display the popup.

Upvotes: 0

Related Questions