Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting the first ever run of an app

I am creating an app in which I have to create a plist when the app launches for the first time. I'm later going to use the plist to store details a user later inputs. How can I detect the first launch of the app? I was experimenting with NSUserDefaults but I think I'm doing something wrong.

like image 588
theNoobProgrammer Avatar asked Oct 13 '11 18:10

theNoobProgrammer


People also ask

How do I know if an app is running for the first time?

There's no reliable way to detect first run, as the shared preferences way is not always safe, the user can delete the shared preferences data from the settings! a better way is to use the answers here Is there a unique Android device ID? to get the device's unique ID and store it somewhere in your server, so whenever ...

What do you call the first screen of an app?

A home screen, homescreen, or start screen, is the main screen on a device or computer program.

How do I find my first app launch Android?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code, we have taken textview, when user open application, it will check whether it is the first time or not.

How do some Android apps remember that this is not the first time they are being installed?

How does an app know it has been installed on a device before? Each device has its unique device ID. So once you have installed an app, they have your device ID and if you try to install again, they'll detect.


1 Answers

You can do this with NSUserDefaults. But be careful with the Version Number.

Do the following:

NSString *bundleVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];

NSString *appFirstStartOfVersionKey = [NSString stringWithFormat:@"first_start_%@", bundleVersion];

NSNumber *alreadyStartedOnVersion = [[NSUserDefaults standardUserDefaults] objectForKey:appFirstStartOfVersionKey];
if(!alreadyStartedOnVersion || [alreadyStartedOnVersion boolValue] == NO) {
    [self firstStartCode];
    [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:YES] forKey:appFirstStartOfVersionKey];
}

the selector firstStartCode will only be called on time for each application version on the very first run.

Okay?

like image 102
Jonas Schnelli Avatar answered Oct 09 '22 05:10

Jonas Schnelli