Search code examples
iosios-simulator

How to simulate iPhone being put to sleep in iOS simulator?


The iPhone app I'm working on seems to exhibit a bug when the phone is put to sleep in the middle of an operation. Is there any way to simulate the phone being put to sleep in the iOS simulator?

Specifically I'm referring to the user pressing the button on the top of the phone next to the headphones which immediately blanks the screen.

NOTE: The OP asked about "turning off" the phone, which is not what happens when you push the button on top. Leaving here since part of getting to the solution is figuring out what question to ask.


Solution

  • Yep. In the menu bar when you've got the iOS Simulator open, Click Hardware -> Lock.

    Note that this looks slightly different than actually sleeping the phone (it keeps the "slide to unlock" screen running), but achieves the same effect.

    You can also do other nifty things like rotate the device and hit the home button.

    To be clear, hitting the home button on the top of the phone doesn't turn it off. It just puts it to sleep.

    When possible, you should always test your app on an actual device. The simulator does not simulate all of the complex OS-level stuff that goes on behind the scenes for background apps and the WatchDog process and that sort of thing.