当设备进入睡眠状态时,哪些ios版本调用applicationWillResignActive,哪些版本调用applicationDidEnterBackground?

发布于 2024-12-23 14:33:39 字数 744 浏览 5 评论 0原文

我已经使用几个设备进行实验确定(据我所知)运行 iOS 4 的 iOS 设备在进入睡眠状态时(或者当用户按下右上角的按钮时,或者当屏幕由于不活动而关闭时)调用 applicationWillResignActive ,但应用程序仍在运行),但运行 iOS 5 的设备在发生这种情况时会调用 applicationDidEnterBackground,并且仅在收到短信/电话或用户拉下通知栏(在其他情况下)之类的情况下调用 applicationWillResignActive文字,非常临时的事件)。

然而,iOS 设备进入睡眠状态并不是一个非常短的事件(可能是一个非常长的事件),因此对于这种情况,我想取消当前的服务器调用,这是我不需要做的(并且不需要不想做)非常短的中断。

我的问题是:有没有办法判断应用程序何时进入睡眠状态,而不是任何其他较短的中断(即短信),和/或,有人知道我上面对 iOS 4 与 5 设备的猜测吗?睡觉时打电话确实正确吗?

这就是我现在在 applicationWillResignActive: 中所拥有的内容:

    if ([[[UIDevice currentDevice]systemVersion] hasPrefix:@"4"] ) { 
        //cancel server call
    }

据我所知,这工作得很好,但是我读过的关于如何确定设备上的 iOS 版本的每个线程都说,如果可能的话,您不应该使用该代码,并且相反,应该为您想要执行的操作调用正确的选择器。但我不知道在这种情况下会发生什么。

I have determined experimentally using a couple devices that (as far as I can tell) iOS devices running iOS 4 call applicationWillResignActive when they go to sleep (either when the user presses the top right button, or when the screen shuts off due to inactivity, but the app is still running), but devices running iOS 5 call applicationDidEnterBackground when this happens, and only call applicationWillResignActive for something like an incoming text message/phone call, or the user pulling down the notification bar (in other words, very temporary events).

The iOS device going to sleep, however, is not a very short event (could be a very long one) and thus for that case I'd like to cancel the current server call, which I don't need to do (and don't want to do) for very short interruptions.

My question is: is there a way to tell when the app has gone to sleep as opposed to any other shorter interruption (ie text message), and/or, alternatively, does anyone know if my guess above about what iOS 4 vs 5 devices call when they go to sleep is indeed correct?

This is what I have right now, in applicationWillResignActive:

    if ([[[UIDevice currentDevice]systemVersion] hasPrefix:@"4"] ) { 
        //cancel server call
    }

This works fine as far as I can tell, but every thread I've read about how to determine iOS version on the device says that you shouldn't use that code if possible, and should instead call the correct selector for what you're trying to do. But I've no idea what that would be in this case.

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

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

发布评论

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

评论(1

暖伴 2024-12-30 14:33:39

在这篇文章中:了解 iOS 4 后台和委托消息传递,您可以找到关于何时发送委托消息的精彩解释。特别是,根据不同的iOS版本,它解释了何时发送applicationWillResignActive和applicationDidEnterBackground。

我希望它对你有帮助。

干杯

In this post: Understanding iOS 4 Backgrounding and Delegate Messaging, you can find an excellent explanation of when the delegate messages are sent. In particular, it explains when applicationWillResignActive and applicationDidEnterBackground are sent, according to different iOS versions.

I hope it helps you.

Cheers

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