我可以在新的一天开始时收到通知吗? [英] Can i get a notification, when a new day begins?

查看:88
本文介绍了我可以在新的一天开始时收到通知吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Cocoa,有一个通知,我可以注册,当一个新的一天开始,在00h:00min:01s在早上通知我?

In Cocoa, is there a notification i can register for, that informs me, when a new day begins - at 00h:00min:01s in the morning?

推荐答案

没有我知道的通知。每当新的一天开始,你可以得到一个定时器:

There's no notification that I know of. You can get a timer to fire whenever a new day begins like so:

[[NSTimer alloc] initWithFireDate:midnight
                         interval:60 * 60 * 24 //one day, in seconds
                           target:someObj
                         selector:@selector(someSelector)
                         userInfo:nil
                          repeats:YES];

诀窍是将 NSDate 设置为午夜。检查

The trick is getting an NSDate set to midnight. Check the Date and Time Programming Guide for how to do that with date components and the like.

编辑:参见这个问题如何获得午夜 NSDate

see this question for how to get the midnight NSDate.

这篇关于我可以在新的一天开始时收到通知吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆