我有多任務問題。我應該知道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