设备时间变化(分钟)时的 NSNotification?

发布于 2024-09-08 13:48:06 字数 119 浏览 4 评论 0原文

有没有办法可以在 iOS 设备的系统时间分钟发生变化时轻松设置通知?

我需要针对时间变化进行一些 UI 更新。我希望 UI 能够准确地更新每分钟的更改,而不是通过 NSTimer 触发器每 60 秒更新一次。

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.

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

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

发布评论

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

评论(1

驱逐舰岛风号 2024-09-15 13:48:06

API 不提供任何通知,但您可以通过让后台线程轮询系统时间,然后向主线程上的 UI 发送自定义通知来推出自己的通知。

不过,我不会打扰。您无法在任何具有软件 UI 的设备上“精确”管理时间。您能做的最好的事情就是让 UI 更新发生在用户感知的阈值以下。人类无法真正感知小于 100-200 毫秒(1/10 秒)的时间间隔。任何更精确的 UI 都是浪费。只要应用程序的其他部分没有挂起或陷入困境,NSTimer 就可以非常可靠地达到 100 毫秒的窗口。

除非您使用 NSTimer 测试了接口并发现它不合要求,否则我不会去寻找增加复杂性的方法。

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.

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