我只是想知道如何计算偶数或一天?我在google上做了一些搜索,但我得到了一些信息来制作这个应用程序,他们告诉我应该使用NSDate和NSCalendar。但是我想存储所有信息,用户可以在重新打开应用程序时加载,我应该使用sqlite还是core数据?感谢
答案 0 :(得分:0)
钟,
1. Store your time (NSDate) at the appropriate time.
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[NSDate date] forKey:@"CheckedInTime"];
[defaults synchronize];
当您的应用再次变为活动状态时: (即) -
(void)applicationDidBecomeActive :( UIApplication *)application
启动计时器以检查时间是否已过期:
self.checkinTimer = [NSTimer scheduledTimerWithTimeInterval:60 target:self selector:@selector(checkinTimerCheck:) userInfo:nil repeats:YES];
- (void) checkinTimerCheck:(NSTimer *) timer {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDate * checkinTime = [defaults objectForKey:@"CheckedInTime"];
float hours = HOWEVER_MANY_HOURS_NEED_TO_PASS_TO_EXPIRE_IN_SECONDS;
if (hours < 0) {
[self alertUserThatTimeHasExpired];
}
}
只要您的应用获得
,就会使计时器检查无效- (void)applicationWillResignActive:(UIApplication *)application
此致
肯