Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my UIApplicationDelegate receive applicationDidBecomeActive when pulling down notification center?

Tags:

ios

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] Resigning active

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

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

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

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

like image 654
Anthony Wieser Avatar asked Jan 03 '18 10:01

Anthony Wieser


1 Answers

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

"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.

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

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

like image 198
DevGansta Avatar answered Oct 20 '22 00:10

DevGansta