- Home /
Turn on/off iOS device's screen via script?
Hi, is there a way to turn on/off an iOS devices' screen via c# script?
What I want to do is to turn the screen off when it is not in use(for example the device is placed on a surface), but keep the application running, and turn the screen on if the device is in use later.
For iOS device if the screen is turned off, it means the device is in 'stand-by' state so you have to manually turn it on by pressing the home button or the power button, and unlock the phone. I don't want the device to be locked when the screen is off, but I don't know how and I don't think Apple offers that functionality. I'm just curious if anyone came up with a solution or something(like jail-breaking).
Answer by Addyarb · Jan 30, 2016 at 08:43 AM
Kind of a hacky solution, but the first thing that comes to mind is:
Create a black texture that fills the screen and set it's alpha to 0 (100% transparent).
Use the front camera and GetPixels to check if most of the pixels are black (i.e. the camera is facing down against a table or something).
Enable the black screen if step 2 is true.
Periodically (using coroutine) check if pixels are not mostly black, and "wake the app up" by then slowly fading out the black screen alpha.
Of course, you'll want to create a bool called something like "isSleeping" and call it if the phone is "sleeping." Then, set all of your rendering to very low quality to save as much battery as possible. At the minimum, I would put a null check in every Update function.
That can be one solution, but it does not 'turn off' the screen. I'm using the device's gyro sensor to check the motion at the moment, and it's much cheaper and faster than checking camera's pixel values. Devices get hot when the screen and backlight are on, and doing so can be a major bottleneck because the devices automatically cut the performance to cool down.
Your answer
Follow this Question
Related Questions
Can't run ANYTHING on iOS. No error messages! 0 Answers
Black screen while running in iOS 4 Answers
Device Auto-Rotation 1 Answer
Cannot run anything in iOS. No errors! 0 Answers
How to obtain physical screen size in iOS simulator? 0 Answers