【发布时间】:2013-03-23 22:04:04
【问题描述】:
我试图找出应用在后台运行的时间。一切都可以正常编译,但我的计数器不会随着应用程序在后台运行的时间而增加。
-(void)applicationWillResignActive:(UIApplication *)application {
closeTime = [NSDate date];
NSUserDefaults *defaultsCloseTime;
[defaultsCloseTime setInteger:closeTime forKey:@"closeTimeKey"];
[defaultsCloseTime synchronize];
}
-(void)applicationWillEnterForeground:(UIApplication *)application {
closeTime = [[NSUserDefaults standardUserDefaults] integerForKey:@"closeTimeKey"];
timeInterval = [closeTime timeIntervalSinceNow] * -100;
}
Counter
在我的视图控制器中:
counterInt = time + counterInt;
【问题讨论】:
-
添加
NSLog(@"Application Did Resign Active");以确保方法被调用。
标签: nsdate nsuserdefaults nstimeinterval