I have tried setting
iPhoneSettings.screenCanDarken = false;
all over my game code, but to no avail… My game will still darken and fall asleep even though I ask it nicely not to.
I have even tried replacing all of those with a Native Function which set idleTimerDisabled = YES
My game continues to fall asleep.
What is up with that?
Hmm, that’s odd. I put iPhoneSettings.screenCanDarken = false; in Awake and in my first scene, and only there, and it works as expected. Where are you putting yours?
Where are you putting this code? Have you tried throwing in a Debug.Log right before / after this line to see if it’s actually being executed?
I ran into the screen darken problem a while back when I put it in the Awake() function and it was not firing. I moved it to Start() and it worked beautifully.
It is in my Awake on an object never set to die starting in Scene 0, also in an OnLevelLoaded even on this object, so every level loaded gets it set there as well.
I now even have a NSTimer set up to set it within Objective C every 5 seconds…
none of this seems to be working
I attach a script to the camera in the first scene with this in it:
function Awake()
{
iPhoneSettings.screenCanDarken = false;
// ... more stuff
}
Try that and let us know how it goes.
Made a script for that sole purpose, added it to the camera in each scene. Did not work as well as one might expect.
Within a minute my app had fallen asleep.
Dude, that is so weird. Just saw where Mattimus had the prob and put his in Start, you tried that?
I mistakenly used Start first from your example above, then used Awake.
Neither work.
Geeze, man that is a drag. I sure wish we could help more, but all I can think of is to try rebooting your iPhone.
Here’s the weird bit, if I “Lock” my iphone while the game is running then “UnLock” it, it doesn’t fall asleep.
I know this is not limited to a single phone needing a reboot as I have 6 ipods I’ve tested this on. All of them are exhibiting the strange behavior. This is definitely the software’s doing.
I got nuthin. Might wanna do a bug report.
So here’s what I found regarding the issue:
I tore all of the screenCanDarken requests in my Unity project and just used my native code to set the idleTimerDisabled property to both NO and YES in an NSTimer every 5 seconds. That worked.
Interesting. On my iPod Touch I don’t have a problem with the app screen darkening, but on the iPhone I do. (I have made a no-touch tilt game…)
Is there anyway to insert Java code to effect the idle timer? Or does it have to be Native? Did apple accept your new native code?
Thanks for the advice.
I had no issues with Apple disliking my solution to the dimming issue. It doesn’t use any weird APIs or anything.
I am not aware of a way to get around this without a native code solution, but you can try to figure out a way, I’d like to know 
One might be able to accomplish something like my native solution with:
void Update{
iPhoneSettings.screenCanDarken = true;
iPhoneSettings.screenCanDarken = false;
}
In order to preserver battery life, I always keep it to true during my menus, and set it to false when the game starts. When the game is paused, I set it to true again.
Never experienced any problems with it… It’s weird that it doesn’t work for you.
Do we agree that for unity 2019 the way to do the same thing would be to use :
Unity - Scripting API: SleepTimeout.NeverSleep ?
Thanks