Wake Lock - stop the phone powering off
What is the simplest way to stop the phone (iPhone) going into an automated sleep mode? I don't mind the screen going off but I want the app to continue running. In android java it is known as a wakelock.
3 Answers
-
Accepted Answer
Place the below in your app.js should do the trick.
Ti.App.idleTimerDisabled = true; // to disable going to sleep
If you want to enable it you just do the following
Ti.App.idleTimerDisabled = false; // to re-enable it
Works on the iPhone, not sure about Android
-
Hmmm??!!
In my App, this works only for some minutes after the iPhone Display is dimming.
Ti.App.idleTimerDisabled = true; setInterval(function(){BeepBeep();},120000); function BeepBeep(){ var date = new Date(); var notification = Ti.App.iOS.scheduleLocalNotification({ sound:"TheTone.caf", date:new Date(new Date().getTime() + 0) // 0 seconds after backgrounding }); };
But then, the iPhone sleeps anyway !
PS: The code here is a part from "bg.js" (Background Service) i first had initialized in app.js with :
var service = Ti.App.iOS.registerBackgroundService({ url:'bg.js' });
What can i do to stop the sleep mode !!
-
Perfect, thanks very much Ben!