2

I am developing an iphone app which ask for one time set up details like user name in the first two screens when the user launches the app for the first time. I dont want these 2 screens to come up when I am launching the app once the user has given the details.

I tried getting the info from internet but I was not able to how to find it out. May be I am missing the technical term or wordings involved in doing this. Could any one please help in accomplishing this scenario. Any sample code would be very helpful.

Thanks for your time

Timothy Rajan
  • 1,947
  • 8
  • 38
  • 62
  • I think this is basically what you are asking: http://stackoverflow.com/questions/308832/iphone-how-do-i-detect-when-an-app-is-launched-for-the-first-time – pasawaya Oct 25 '13 at 00:24

4 Answers4

2

Just set a boolean variable to the user-defaults. The user-defaults is a way to save information to the phone, external from the application, that the app can call upon whenever you want.

Inside your app-delegate when it boots, check the user-defaults for a boolean.

To save a boolean to user-defaults:

NSValue *state = ... //Whatever state you want. NSValue allows for booleans.
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:obj forKey:@"notFirstTimeRun"];
[defaults synchronize];

To load the boolean from user-defaults:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSValue *state = [defaults objectForKey:@"notFirstTimeRun"];

Do a check:

if ([state boolValue] == true){
     //Has ran before, skip your UIViews or whatever
}
else{
     //Has not ran before, do your setup or whatever.
}
Ospho
  • 2,756
  • 5
  • 26
  • 39
  • This is indeed the best way, though if the user ever removes the app from the phone, he / she will have to go through the setup process once again. This might seem a bit redundant if the setup info is linked to an account on a remote server, but otherwise makes sense. – Wolfgang Schreurs Oct 25 '13 at 01:15
0

What you are looking to do is basically store a flag that dictates whether the user has gone through the setup steps. And upon app launch, you check to see if that flag exists with the respective value to denote whether or not to show a setup screen. NSUserDefaults provides a really simple, easy way of persisting state across sessions.

Stunner
  • 12,025
  • 12
  • 86
  • 145
0

This is how I would do it:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasBeenLaunched"]){
        // This is not the first time, therefore open app as usual
    } else {
        // This is the first time, show special views
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasBeenLaunched"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
}
Daniel Larsson
  • 6,278
  • 5
  • 44
  • 82
0

How about setting a bool in AppDidFinishLaunching. You can check that bool everytime the app is launched and show or hide respective screen based on that.

azmuhak
  • 964
  • 1
  • 11
  • 31