Lebron Tang
Lebron Tang

Reputation: 31

How to detect the very first run in an ios app?

I've search a lot of that and as conclusion:

But as far as I know, all these ids can be change by users, and keychain can be disabled in icloud setting. Some says use NSUserDefault but this will be removed once remove the app.

What I want to achieve is detect first run on a specific device even uninstall and reinstall.

I am new to ios dev, can some one help? thanks in advance.

Upvotes: 0

Views: 141

Answers (2)

Aatish Rajkarnikar
Aatish Rajkarnikar

Reputation: 201

Getting the Vendor-ID and storing it to Keychain is the best way you can achieve your requirement.

Upvotes: 1

Chris Wagner
Chris Wagner

Reputation: 21013

Try reading a key out of UserDefaults that you know won't exist.

if UserDefaults.standard.bool(forKey: "YourAppNamePrefixHasRunBefore") {
  // do whatever you need to do
  UserDefaults.standard.set(true, forKey: "YourAppNamePrefixHasRunBefore") // set the key so on the next run this test fails 
}

You may need to validate syntax, but it should be pretty close.

Upvotes: 0

Related Questions