要获得安装日期,检查Documents文件夹的创建日期。
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);
为了得到最后的应用程序更新日期,检查应用程序的修改日期捆绑本身
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);
你是怎么解决这个问题的?如何检查最后修改日期? – Brandon 2010-11-11 12:47:38
它似乎还没有解决,因为我的程序中有一些其他的错误,它现在工作的很好。我不知道如果用户删除应用程序然后在未来恢复它,会发生什么,但我找不到更好的方法。 – felace 2010-11-17 14:03:40
你看看@medTechy的答案,我认为检查用户应用程序文档目录的创建日期似乎是正确的解决方案!? – 2013-10-28 19:08:04