ios 4.3.1 applicationWillResignActive behavior bug?
The Apple docs for this event states:
This method is called to let your application know that it is about to move from the active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. An application in the inactive state continues to run but does not dispatch incoming events to responders.
I am seeing behavior that is at variance with the last senten开发者_运维问答ce. If I run an app under the XCode debugger that collects and logs data in response to a timer firing, the data collection and logging continues indefinitely if I press the Sleep/Wake button to put the device to sleep.
However, if I run the app "normally" (ie, not in the XCode debugger) then data collection and logging stops almost immediately after the device is slept.
The Apple docs also say (emphasis mine)
You should use this method to pause ongoing tasks, disable timers and throttle down OpenGL ES frame rates.
But doesn't really explain why timers should be disabled.
I'm trying to figure out if the observed behavior (the inactive state seems to stop my timer, and/or possibly the entire app) is a bug or not, or if the docs are wrong about an application running while inactive, or why the behavior of the app under the debugger is different from the "real world" behavior.
Any help or clarification would be appreciated.
Read about the various application states for insight into this. Apps don't usually stay in the inactive state for very long, but switch to either background or suspsended states.
I (finally!) found a thread that seems to explain what I'm seeing:
What happens to an iPhone app when iPhone goes into stand-by mode?
It appears the difference in behaviors isn't tied to XCode, but is instead because the device is attached via USB (to allow debugging), so iOS never sleeps after the screen is locked because it's plugged in and charging.
If the device is not plugged in, then a short time after the screen is locked (approx 20 seconds), the device sleeps: all activity on the main CPU halts.
So the Apple docs aren't wrong, just incomplete in not stating the inactive -> slept transition that takes place.
(Should I delete this question?)
精彩评论