当我将我的应用程序置于后台模式时,我保存了一个值NSUserDefaults
,然后当应用程序再次激活时,该值是不同的。
我保存值:
- (void)appDidEnterBackground:(NSNotification *)notification {
//Tiempo inicial de inactividad
NSUserDefaults *dispositivo = [NSUserDefaults standardUserDefaults];
NSTimeInterval timestamp = ([[NSDate date] timeIntervalSince1970] * 1000);
[dispositivo setFloat:timestamp forKey:@"StartBackground"];
NSLog(@"Start background: %f", timestamp);
[[NSUserDefaults standardUserDefaults] synchronize];
}
日志:启动后台:1418731653366.276123
我想恢复价值:
- (void)appDidBecomeActive:(NSNotification *)notification {
NSUserDefaults *dispositivo = [NSUserDefaults standardUserDefaults];
NSTimeInterval startDate = [dispositivo floatForKey:@"StartBackground"];
NSLog(@"Start date: %f", startDate);
}
日志:开始日期:1418731716608.000000
这是我使用这个值的唯一地方。谢谢你的提前。