要獲得安裝日期,檢查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