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

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.

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.

As of 2021 to lock the simulator's screen:
Device -> Lock
or
Cmd + L

Related

iOS 11 Single App Mode, Disable lock screen

I'm working on developing a kiosk app to run in single app mode on two 12.9" iPad Pros. We want the option to turn these kiosks off so I'm using the ionic-native Insomnia and Battery-Status plugins to keepAwake when it is plugged in and allowSleepAgain when it is unplugged.
The problem is, the enclosures that were selected to house the iPads completely block all of the buttons, including the home button. When the iPads are plugged back in, the screen turns on and shows the "Press Home to Open" screen. To actually hit the home button, we need to get a key and remove the iPad from the enclosure.
Is there any way, either through the standard iPad preferences, or through the Configurator/Single App Mode preferences, to bypass the lock screen and go directly into the app when it wakes up?
I know I could probably find a way to setBrightness to 0 when unplugged and to 100 when plugged back in. But, that seems less preferable to me than letting it actually go to sleep.
Thanks

Xcode9 made my Iphone7 screen go black

I launched an app with my own iphone7. the app had nothing on it. It is a single page application in IOS. when I ran the app it made my phone's screen go black. I can still get messages and it makes sounds, but the screen is black so I can not use it. How can I fix it?
I assume you're still running the app itself, and because your app has no content, it shows a black screen by default. If that's the case, you can forcibly terminate the app by double-tapping on the Home button, and then swiping down on the problematic app.
As an alternative, you could try soft resetting the device itself, by holding the Sleep button and the Home button at the same time for 10 seconds.
As a last resort, you can hard reset the device under Settings -> General -> Reset -> Erase All Content And Settings. Note that this will erase everything on the device, so should only be attempted if nothing else works.

What is the proper UX for user to exit an iPhone app?

Is the iPhone "device Home button" (circle button that is part of the hardware at bottom center) the standard way that users exit an iPhone app?
I don't have an actual iPhone device yet (looking for the iPhone6 to come down in price a bit), am just working with Xcode simulators. When I run my iPhone Swift apps, they are always in full screen mode.
On Android, there are a few navigation buttons built into the OS that appear at the bottom of the screen - Back, Home, Open Apps. And in that OS you can give a directive to exit full screen to reveal those OS buttons.. which then allows the user to easily exit the app if they'd like to.
In looking at the iPhone apps on the simulator, I notice they don't have this kind of UX.
What are the best practices around iPhone users
A. Sending an app to the background ?
B. Quitting/Closing an app ?
To send an app to the background, hitting the home button is sufficient.
To quit an app, tapping the home button twice shows you all the open apps; you can then swipe an app to "kill" (terminate) it.
However, here is a recent post by the excellent John Gruber explaining why killing an app should only be a last resort: https://daringfireball.net/2017/07/you_should_not_force_quit_apps
Note: on the iPhone Simulator, the command-shift-H key combo is equivalent to hitting the home button.
To send an app to the background:
Press the Home button.
To "quit" or "close" an app:
Press the Home button.
That's all the UX expected of an iOS app... and none if it is actually provided by your app. iOS manages it for you; you just have to deal with your app's lifecycle methods to respond to the user leaving and re-entering your app.
iOS doesn't expect users to know or care about the difference between "background" and "closed/quit" in most cases. You enter an app, you leave an app, that's it.
And the way iOS works under the hood, there is no difference in most cases — when you leave an app, it's not "running in the background", it's "frozen" or "suspended": that is, in memory but not running. That way the OS can get it usable again near-instantly if the user comes back, or instantly reclaim that memory if another process needs it.
The user can also invoke the multitasking UI (double click home button, or in iOS 11 on iPad swipe up from bottom edge) and swipe an app away, but this is equivalent to the "kill" or "force quit" actions seen in other operating systems — it's primarily for situations where an app is misbehaving. This isn't part of your app's UX either; it's also provided by iOS.
As noted in the Daring Fireball post linked from #TimKokesh's answer, there are some circumstances where an app "in the background" isn't "frozen" but has some limited ability to run, the Settings app has UI to help the user keep tabs on what are using (and abusing) that ability, and those are some of the only cases where it's reasonable for a user to "force quit" apps.
If you want to have a real iPhone look-alike simulator on your development environment, yes it's available with New Xcode-9/Beta version. It shows real hardware buttons(volume, lock, home buttons) which you can press and feel like a real device. If you are interested you can download it from here
On other Xcode environments, you can go to home screen by pressing the keys: Cmd + Shift + H

Xcode 5 and iPhone 5S - Running app "crashes" device (sort of)

I'm creating a new app. Very, very initial stages (i.e., it literally has no custom code yet). All I've done so far is a basic implementation of Urban Airship's libraries.
Sometimes (about 50% of the time?), when I push the app to my device, the following occurs:
App doesn't load on device
Xcode reports "failed to get task for process"
Device exhibits odd behavior.
"Odd behavior" includes:
Device wallpaper disappears and is replaced with an all black background.
Tapping on any icons gives them a pressed/shadowed look, but nothing happens.
Tapping on the icon again sets it back to its normal state. Again, nothing else.
Pressing home button does nothing.
Pressing lock button will lock device, but no attempt to unlock the device (home button or lock/unlock button) has no effect.
Attempting to use Siri gives the initial sound, but nothing further.
Hard rebooting the device gets it functional again. There doesn't seem to be a pattern to when this "bug" appears.
Has anyone else encountered this "bug"?

How can I autolock / awaken an iPad if the home button is disabled or covered?

I am building an iPad Kiosk App and my customer wants the iPad to be "locked into" the app to keep users focused :) I have found two solutions to this. One is a lovely kiosk case which covers the home button, the other is setting SBStoreDemoAppLock as outlined in http://rick-hawkins.blogspot.co.il/2012/01/turning-ipad-into-kiosk-device.html
But the customer is also worried about screen burnout (and burn in) and wants to be sure the iPad goes to sleep, or at the very least to a screen saver, when inactive. If I have disabled the home button though, I cannot let the iPad go to sleep because it cannot be woken again. Ideally touching the screen would awake the iPad and go straight back into the app.
Is there a solution that doesn't involve me creating a fake sleep feature or screen saver as part of my app?
I would not worry about "burn-in", these aren't CRTs from the 1980s. Also, it has been announced that this type of feature will be available in iOS 6.0, so you may want to wait a few months and use 6.0.

Resources