iOS 设备空闲,网络停止。我如何收到有关进入“空闲”状态的通知?状态?

发布于 2024-09-27 09:46:40 字数 242 浏览 3 评论 0原文

我的应用程序有一个屏幕,它不断轮询服务器以获取信息。 当用户不与应用程序交互时,它会处于空闲状态,屏幕会变暗,然后变黑。

在后台,应用程序仍然尝试轮询服务,但从 NSURLConnection 获取 -1009 错误代码。 (-1009 == NSURLErrorNotConnectedToInternet)

我的想法是,一旦应用程序进入空闲状态,就停止轮询服务器以获取信息。

当设备进入空闲状态时,有没有办法收到通知?

My app has a screen where it is constantly polling a server for information.
When the user does not interact with the app it goes idle, the screen goes dim and then black.

In the background, the app still tries to poll to service, but gets -1009 error codes from NSURLConnection. (-1009 == NSURLErrorNotConnectedToInternet)

My idea is to stop polling to server for information, once the app enters this idle state.

Is there a way to get notified, when the device enters the idle state?

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

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

发布评论

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

评论(1

短叹 2024-10-04 09:46:40

如果屏幕被锁定,您将通过以下方式收到通知;

- (void)applicationWillResignActive:(UIApplication *)application

苹果文档

If the screen gets locked you will be notified by the following method;

- (void)applicationWillResignActive:(UIApplication *)application

Apple documentation

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