ICoder
ICoder

Reputation: 1347

how to display a alert display only on the application launch first time?

Ha ii everybody i am doing a reader application which has so many functionality in it,pinch gesture for search function,swipe right and left for the previous and next page,tap to hold for the chapter selection view like that,but when the user download the application and use it we have to inform these functionality with a alert-view or a simple pop-up for the application very first launch.I saw it in many reader applications ,i know this is done through NSNotification or something like that,but i dont know how to use this ,please help me to do this. Thanks in advance.

Upvotes: 1

Views: 619

Answers (2)

SEG
SEG

Reputation: 1715

In case you mean a UIAlertView, thats pretty easy. But if you want a nice looking view notifying the user about different features, maybe add a view controller of which view has all these things and a get started button on it.
Use NSUserDefaults to store if the user has entered the application for the first time as in the link which EI Developer suggested. In your AppDelegate Class add your changes to this method.

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],@"firstLaunch",nil]];

    //If First Launch
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]) {
        //Show welcome view
        [self.window addSubview:[welcomeScreen view]];
    }
    else {
        [self.window addSubview:[startUpViewController view]];
    }
    [self.window makeKeyAndVisible];
}

Add another method in your AppDelegate which the welcomeScreen class can call when the user presses the get started button

- (void) getStarted {
    [[welcomeScreen view] removeFromSuperview];
    [self.window addSubview:[startUpViewController view]];
}

In your welcomeScreen class add an IBAction which calls this method.

- (IBAction) getStartedPressed {
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [appDelegate getStarted];
    //set firstLaunch to NO
    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"firstLaunch"];
}

Dont forget to add the AppDelegate #import header in your welcomeScreen class

Upvotes: 2

El Developer
El Developer

Reputation: 3346

You can probably use the code found in this question:

iPhone: How do I detect when an app is launched for the first time?

Hope it helps! :D

Upvotes: 1

Related Questions