iPhone应用程序如何解决应用程序关闭时计时器暂停的问题?

发布于 2024-11-10 12:04:27 字数 180 浏览 5 评论 0原文

目前我正在使用计时器来执行计算,然后每秒更新一个标签,但是一旦iPhone应用程序被发送到后台,计时器就会暂停,然后在重新打开时恢复...我有什么选择来解决这个问题这样看来计时器还没有停止?

--- 目前试图记录应用程序停止然后重新打开的时间,这些值之间的差异并将差异添加到标签中,但没有运气:(

感谢任何帮助!

at the moment i am using a timer to perform a calculation and then update a label every second but once the iphone app is sent to the background the timer pauses and then resumes upon re-opening... what are my options to get around this so that it seems the timer has not stopped ??

--- at the moment trying to record the time in which the app stops and then reopens, that the difference between those values and add the difference to the label but having no luck :(

ANY HELP IS APPRECIATED !!!

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

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

发布评论

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

评论(1

满意归宿 2024-11-17 12:04:27

当应用程序移至后台时(即您的应用程序委托收到 applicationDidEnterBackground: 消息,或者您收到 UIApplicationDidEnterBackgroundNotification 通知),只需停止计时器即可。如有必要,请保存当前时间。

然后,当应用程序移动到前台时(即您的应用程序委托收到 applicationWillEnterForeground: 消息,或者您收到 UIApplicationWillEnterForegroundNotification 通知),从当前的标签值重新计算时间,然后重新启动计时器。

When the app moves to the background (i.e. your app delegate gets the applicationDidEnterBackground: message, or you receive a UIApplicationDidEnterBackgroundNotification notification), just stop the timer. And save the current time, if necessary.

Then when the app is moving to the foreground (i.e. your app delegate gets the applicationWillEnterForeground: message, or you receive a UIApplicationWillEnterForegroundNotification notification), recalculate the the label value from the current time and then restart the timer.

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