我试图找出应用程序在后台运行的时间。一切都编译得很好,但是我的计数器不会随着应用程序在后台运行的时间而增加。
-(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;