自从上次在iOS上打开应用程序多久以来? [英] How long since last time app was opened in iOS?
本文介绍了自从上次在iOS上打开应用程序多久以来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何判断我的应用上次开启时的时间?即使我的应用程序没有在后台运行,这仍然可以监控吗?
How can I tell the time from the last time my app was open? Can this still be monitored even my app is not running in the background?
谢谢。
推荐答案
点击
[[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:@"kLastCloseDate"];
两者
- (void)applicationWillTerminate:(UIApplication *)application
- (void)applicationDidEnterBackground:(UIApplication *)application
然后检查启动时的差异:
Then check the difference at startup:
NSDate *lastDate = [[NSUserDefaults standardUserDefaults] objectForKey:@"kLastCloseDate"];
NSTimeInterval timeDiff = [[NSDate date] timeIntervalSinceDate:lastDate];
// your stuff
两个
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- (void)applicationWillEnterForeground:(UIApplication *)application
这篇关于自从上次在iOS上打开应用程序多久以来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文