简体   繁体   中英

applicationWillResignActive how to test on iPhone simulator

My iPhone application has code that handles the event for when the iPhone falls asleep, and re-awakens. My question is, how do I test this using either the iPhone or the simulator. Is there a hotkey or command to force the phone or simulator to fake "go to sleep?".

Thanks.

Yes, Command-L ("Lock" on the "Hardware" menu) will lock the simulator.

It will not go to sleep, but according to the documentation , this should be enough to trigger the "applicationWillResignActive" method:

"The delegate can implement this method to make adjustments when the application transitions from an active state to an inactive state. When an application is inactive, it is executing but is not dispatching incoming events. This occurs when an overlay window pops up or when the device is locked."

If you press Command-L ("Lock" on the "Hardware" menu) it will trigger -applicationWillResignActive: AND -applicationDidEnterBackground: methods.

If you want to test just -applicationWillResignActive: method you can double press home button (or double press Command-H) to trigger App switcher. In this case only -applicationWillResignActive method is called.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM