Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine the date an app is installed or used for the first time?

Tags:

I'm planning on opening up an in app store and I'd like to give existing users some of the items for free.

I thought of releasing an update which would store some informaion the first time the app is used, then release the "real" update that'd look if the app was purchased before, however, it's likely that not everyone will opt for the first update.

So, is there a way to find out when exactly a user has first installed (or used) the app ?

Update :

Thanks for the answers, but I should make the it less ambiguous :

I'm looking for a native call/anything similar to do it. Since the app is already on store and I haven't set up anything to store the data on the first version, an update will help me do what I want if all the users grab it before the second update is released : It'd be impossible to distinguish a new user from an existing one who had missed the intermediary update and has just updated to the most recent one.

like image 855
felace Avatar asked Nov 03 '10 18:11

felace


2 Answers

To get the installation date, check the creation date of the Documents folder.

NSURL* urlToDocumentsFolder = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; __autoreleasing NSError *error; NSDate *installDate = [[[NSFileManager defaultManager] attributesOfItemAtPath:urlToDocumentsFolder.path error:&error] objectForKey:NSFileCreationDate];  NSLog(@"This app was installed by the user on %@", installDate); 

To get the date of the last App update, check the modification date of the App bundle itself

NSString* pathToInfoPlist = [[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"]; NSString* pathToAppBundle = [pathToInfoPlist stringByDeletingLastPathComponent]; NSDate *updateDate  = [[[NSFileManager defaultManager] attributesOfItemAtPath:pathToAppBundle error:&error] objectForKey:NSFileModificationDate];  NSLog(@"This app was updated by the user on %@", updateDate); 
like image 125
Drew H Avatar answered Nov 09 '22 13:11

Drew H


NSDate *installDate = [[NSUserDefaults standardUserDefaults]objectForKey:@"installDate"];  if (!installDate) {     //no date is present     //this app has not run before     NSDate *todaysDate = [NSDate date];     [[NSUserDefaults standardUserDefaults]setObject:todaysDate forKey:@"installDate"];     [[NSUserDefaults standardUserDefaults]synchronize];      //nothing more to do? } else {     //date is found     NSDate *todaysDate = [NSDate date];     //compare todaysDate with installDate     //if enough time has passed, yada yada,     //apply updates, etc. } 
like image 32
Daddy Avatar answered Nov 09 '22 14:11

Daddy