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

后端 未结 10 606
慢半拍i
慢半拍i 2020-12-03 01:40

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

10条回答
  •  孤城傲影
    2020-12-03 02:08

    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);
    

提交回复
热议问题