iphone倒计时事件

iphone倒计时事件,iphone,count,nsdate,Iphone,Count,Nsdate,我只想知道如何为一个偶数或一天倒计时?我在谷歌上做了一些搜索,但我得到了一些信息来制作这个应用程序,他们告诉我应该使用NSDate和NSCalendar。但是我想存储所有信息,用户可以在重新打开应用程序时加载,我应该使用sqlite还是核心数据?谢谢你,本 1. Store your time (NSDate) at the appropriate time. NSUserDefaults *defaults = [NSUserDefaults standardUserDefa

我只想知道如何为一个偶数或一天倒计时?我在谷歌上做了一些搜索,但我得到了一些信息来制作这个应用程序,他们告诉我应该使用NSDate和NSCalendar。但是我想存储所有信息,用户可以在重新打开应用程序时加载,我应该使用sqlite还是核心数据?谢谢你,本

1. Store your time (NSDate) at the appropriate time.
        NSUserDefaults  *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:[NSDate date] forKey:@"CheckedInTime"];
        [defaults synchronize];
  • 当你的应用再次激活时: (即)—

    (无效)应用IDBECOMEACTIVE:(UIApplication*)应用

  • 启动计时器检查时间是否已过期:

     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