0

In an iOS Application, what is the best way to determine an application was downloaded for the first time. Is their some programatic way of telling that its the first time running it?

The idea behind this is that their is a method that would run differently based on wether they have just downloaded it or have been using the application for a while. I have seen this many times where an app loads and their is an overlay for the 1st time giving a tour.

My use/case is different but I couldnt figure out a way of telling if it was first launched. Is this possible in iOS?

logixologist
  • 3,694
  • 4
  • 28
  • 46

3 Answers3

2

Check for a flag in NSUserDefaults (use NSNumber since you can get a BOOL from it). If it's not there, it's first run, in which case you set the flag.

Shaggy Frog
  • 27,575
  • 16
  • 91
  • 128
1

There is no way provided by the system itself, but you can simply check for the non-existence of a key in the NSUserDefaults, or the non-existence of a file. Obviously, you would then have to create mentioned key or file.

If your use case is tied to data to begin with, eg. requiring an account of some sort, you can simply check wether there is a keychain entry for the account (or whatever way you chose to store the account credentials)

JustSid
  • 25,168
  • 7
  • 79
  • 97
1

Code for NSUserDefaults. you need to check in didFinishLaunchingWithOptions method

if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"])
    {
        // app already launched
    }
    else
    {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        // This is the first launch ever            
    }
Maulik
  • 19,348
  • 14
  • 82
  • 137