开发者

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 开发者_Python百科a alert view popup when my apps run first time in iphone. I'm not getting how to do this. Please someone help me.


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

Edit: What Akshay said earlier, with some code.


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"];
    }
}


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.


Put the alertview code in didFinishLaunchingWithOptions function in delegate.m


NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜