iPhone倒计时事件

发布于 2024-10-28 02:06:30 字数 138 浏览 1 评论 0原文

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

I just want to know how to make a count down for a even or a day? i did some search on google but I got got some few information to make this application ,they told me should be using NSDate and NSCalendar.however I want to stored all information and user can load when reopen the application ,should I using sqlite or core data? thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

林空鹿饮溪 2024-11-04 02:06:30

Ben,

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

    (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

Ken

Ben,

1. Store your time (NSDate) at the appropriate time.
        NSUserDefaults  *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:[NSDate date] forKey:@"CheckedInTime"];
        [defaults synchronize];
  1. When your app become active again:
    (i.e.) -

    (void)applicationDidBecomeActive:(UIApplication *)application

Start a timer to check to see if the time has expired:

 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];
    }
}

Invalidate the timer check whenever your app gets

- (void)applicationWillResignActive:(UIApplication *)application

Regards,

Ken

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文