NSNotification when device time changes (minutes)?

被刻印的时光 ゝ 提交于 2020-01-14 02:10:10

问题


Is there a way I can easily set up a notification when the minutes change on the system time for iOS devices?

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.


回答1:


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.

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.

Unless you've tested the interface using a NSTimer and found it wanting, I wouldn't go looking for adding complexity.



来源:https://stackoverflow.com/questions/3180920/nsnotification-when-device-time-changes-minutes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!