且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检测首次启动iOS应用程序的时间?

更新时间:2023-01-25 22:02:04

几乎是Marc和Chris所说的虽然我更喜欢在应用程序退出时更改值,以防应用程序的多个区域需要了解它。
代码:

Pretty much what Marc and Chris said, though I prefer to change the value when the app quits in case there're multiple areas of the application that need to know about it. In code:

// -applicationDidFinishLaunching:
[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],@"firstLaunch",nil]];
// to check it:
[[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"];
// -applicationWillTerminate:
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"firstLaunch"];