我有多任务问题。我应该知道iPhone在将应用程序放到背景后经过了多少秒钟。我尝试使用带有NSDate对象的applicationDidEnterBackground
和applicationWillEnterForeground
,但无法成功获取时间。计算iphone应用程序的背景和前景之间的时间?
任何人都可以帮助我吗?
编辑:
- (void)applicationDidEnterBackground:(UIApplication *)application {
backgroundDate = [NSDate date];
NSLog(@"background time= %@", backgroundDate);
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
//– timeIntervalSinceNow
NSLog(@"background time2= %@", backgroundDate);
NSDate *date = [NSDate date];
NSLog(@"foreground time= %@", date);
}
日志:
2011-03-23 12:47:58.405 Sanal Market[1783:207] background time= 2011-03-23 10:47:58 +0000 2011-03-23 12:48:00.730 Sanal Market[1783:207] background time2= <CAContextImpl: 0x5416e10> 2011-03-23 12:48:00.731 Sanal Market[1783:207] foreground time= 2011-03-23 10:48:00 +0000
哪来的问题? – ryyst 2011-03-23 10:28:18
我想serhats想知道如何获得在applicationDidEnterBackground和applicationWillEnterForeground事件之间传递的持续时间。 – 2011-03-23 10:35:46
这是rijht Vaibhav Tekam。问题是我不知道该怎么做。 – serhats 2011-03-23 10:38:35