当设备时间改变(分钟)时,NSNotification? [英] NSNotification when device time changes (minutes)?
问题描述
有没有一种方法可以在iOS设备的系统时间更改分钟数时轻松设置通知?
Is there a way I can easily set up a notification when the minutes change on the system time for iOS devices?
我需要进行一些UI更新以更改时间.我希望用户界面能够根据分钟的变化进行精确更新,而不仅仅是通过NSTimer触发器每60秒更新一次.
I need to do some UI updates for time changes. I'd like the UI to update exactly on minute changes, not just every 60 seconds through an NSTimer trigger.
推荐答案
API没有提供任何通知,但是您可以通过让后台线程轮询系统时间然后将自定义通知发送到UI来进行滚动主线程.
There are no notifications provided by the API but you could roll your own by having a background thread polling the system time and then sending a custom notification to the UI on the main thread.
但是,我不会打扰.您无法在带有软件UI的任何设备上完全"管理时间.您能做的最好的事情就是让UI更新发生在用户感知的阈值以下.人类无法真正感知不到100-200毫秒(1/10秒)的时间间隔.任何更精确的用户界面都是浪费的.只要应用程序的其他部分没有挂起或停滞,NSTimer就能非常可靠地命中100毫秒的窗口.
However, I wouldn't bother. You can't manage time "exactly" on any device with a software UI. The best you can do is get the UI updates to occur below the threshold of user perceptions. Humans can't really perceive time intervals of less than 100-200 milliseconds (1/10th second). Any UI more precise is wasted. A NSTimer can very reliably hit a 100 millisecond window as long as some other part of the app doesn't hang or bog.
除非您已经使用NSTimer测试了接口并发现它有需要,否则我不会去寻找增加复杂性的方法.
Unless you've tested the interface using a NSTimer and found it wanting, I wouldn't go looking for adding complexity.
这篇关于当设备时间改变(分钟)时,NSNotification?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!