为什么下拉通知中心时,我的UIApplicationDelegate为什么会收到applicationDidBecomeActive? [英] Why does my UIApplicationDelegate receive applicationDidBecomeActive when pulling down notification center?

查看:154
本文介绍了为什么下拉通知中心时,我的UIApplicationDelegate为什么会收到applicationDidBecomeActive?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在XCode中构建了一个没有功能的裸应用程序,并将日志记录语句放置在applicationDidBecomeActive和applicationWillResignActive方法中.

I've built a bare application with no functionality in XCode, and put logging statements in the applicationDidBecomeActive and applicationWillResignActive methods.

当我向下滑动以显示通知中心时,会看到以下内容:

When I swipe down to show the notification center, I see the following:

2018-01-03 10:18:16.867028 + 0000 BareProject [1165:2053601]主动退出

2018-01-03 10:18:16.867028+0000 BareProject[1165:2053601] Resigning active

2018-01-03 10:18:17.510713 + 0000 BareProject [1165:2053601]活动

2018-01-03 10:18:17.510713+0000 BareProject[1165:2053601] Active

2018-01-03 10:18:17.634805 + 0000 BareProject [1165:2053601]主动退出

2018-01-03 10:18:17.634805+0000 BareProject[1165:2053601] Resigning active

这是故意的吗?我的代码在变为活动状态时做了很多工作,只是在大约120ms之后再次将地毯从中拉出,看来该文档说我应该使用applicationDidBecomeActive重新启动任务: https://developer.apple.com/documentation/uikit/uiapplicationdelegate /1622956-applicationdidbecomeactive?language = objc

Is this intended? My code does quite a lot of work when becoming active, only to have the rug pulled out from it again about 120ms later, and it seems that the documentation says I should be using applicationDidBecomeActive to restart tasks: https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622956-applicationdidbecomeactive?language=objc

我在ios 10.3上尝试过此操作,此行为不存在.

I tried this on ios 10.3 and this behavior does not exist.

推荐答案

实际上存在两个问题,对applicationDidBecomeActive:的意外调用和对applicationWillResignActive:的重复调用.

There are actually two issues, the unexpected call to applicationDidBecomeActive: and the duplicated call to applicationWillResignActive:.

下拉"以显示用于在iOS 9上正常运行的通知中心.只有applicationWillResignActive:曾经被系统调用,只是通过iOS 9 Simulator进行了验证.

"Pull down" to show a notification center used to work properly on iOS 9. Only applicationWillResignActive: used to be called by the system, just verified it with iOS 9 Simulator.

在iOS 11.2.6上,按照您所描述的那样调用applicationDidBecomeActive:,这似乎是一个Apple bug.在这种特殊情况下,系统行为与文档冲突.这是文档偏离您观察到的行为的另一个示例

On iOS 11.2.6, the applicationDidBecomeActive: gets called as you described which seems like an Apple bug. In this particular case, the system behavior conflicts with the documentation. Here is another example where the documentation deviates from the behavior you observed https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/StrategiesforHandlingAppStateTransitions/StrategiesforHandlingAppStateTransitions.html#//apple_ref/doc/uid/TP40007072-CH8-SW10

当您的应用移回活动状态时,其 applicationDidBecomeActive:方法应逆转任何步骤 取自applicationWillResignActive:方法.

When your app is moved back to the active state, its applicationDidBecomeActive: method should reverse any of the steps taken in the applicationWillResignActive: method.

这篇关于为什么下拉通知中心时,我的UIApplicationDelegate为什么会收到applicationDidBecomeActive?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆