Show screen on first launch only in iOS

I'm assuming by Xcode you actually mean iOS.

What you need to do is use the NSUserDefaults class to store a flag indicating whether the user has seen the tutorial screen before.

When your app first loads (or at the point you want to decide whether or not to show the tutorial screen), do something like this:

if(![[NSUserDefaults standardUserDefaults] boolForKey:@"hasSeenTutorial"])
    [self displayTutorial];

This checks the saved NSUserDefaults for the current user for a value named "hasSeenTutorial", which won't exist yet. Since it doesn't exist, it will call displayTutorial. displayTutorial refers to your method for creating the tutorial view. You can figure out that part.

Then, once the user closes the tutorial screen:

[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"hasSeenTutorial"];

That value will be saved for your user profile, meaning the next time it checks it, it will be true, so displayTutorial won't be called.


In your viewDidLoad:

if (![@"1" isEqualToString:[[NSUserDefaults standardUserDefaults]
                                objectForKey:@"aValue"]]) {
    [[NSUserDefaults standardUserDefaults] setValue:@"1" forKey:@"aValue"];
    [[NSUserDefaults standardUserDefaults] synchronize];

    //Action here

}

Certainly, if we would like to tell user something about features after update (not only app launched first time), the solution below could be suitable.

In your viewDidLoad:

NSString *currentBundleVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
NSString *previousBundleVersion = [[NSUserDefaults standardUserDefaults] objectForKey:@"PreviousBundleVersion"];

if (![currentBundleVersion isEqualToString:previousBundleVersion] ) {
     // Here you can initialize your introduction view and present it!
}

Once the user closes the intro:

NSString *currentBundleVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];    
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];

if (standardUserDefaults) {
    [standardUserDefaults setObject:currentBundleVersion forKey:@"PreviousBundleVersion"];
    [standardUserDefaults synchronize];
}

In this case app bundle version stored in your standardUserDefaults will be differ from current bundle version only after update and shown only once as well as at first launch.


Initialise your user defaults with a BOOL, something called instructionsSeen (or whatever you want) and set it to NO in your App delegate's initialize method.. In your app, test this value and if it is NO display your tutorial screen. As part of showing and displaying this screen, set the instructionsSeen to YES and store it in your defaults.

This way the demo screen will only show on first launch, unless the user uninstalls and installs the app again.

You could also show the demo for a small number of launches (say 3). In this case, don't use BOOL use a number and increment it instead.