Reputation: 23
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
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
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
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
Reputation: 13180
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if([defaults objectForKey:@"FirstTime"] == nil)
{
//your alert message
}
[defaults setObject:@"firsttime" forKey:@"FirstTime"];
Upvotes: 0
Reputation: 1433
Put the alertview code in didFinishLaunchingWithOptions function in delegate.m
Upvotes: 0
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