Closed SimonBowyer closed 9 years ago
Hi,
Since I don't have your entire project let's try to figure out if this is really a problem with the plugin first. Can you add this to your index.html and not press any button?
document.addEventListener('deviceready', function() {
alert('deviceready fired, keeping the screen on - dismiss me and wait');
window.plugins.insomnia.keepAwake()
}, false);
Hi Eddy
That worked so not sure what I'm doing incorrectly.
While researching this and other solutions, it has become apparent that this technique may not be allowed under the Apple application rules. In your experience, is this correct for this plugin? If it is, this solution isn't going to be possible for us after all.
Thanks Simon
Apple has no problem with this as long as you don't block sleeping more than really necessary.
As an example: the official PhoneGap Developer App uses this plugin so the device stays awake while you're remotely reloading your app.
Thanks Eddy
Still got the same issue though. Are there any circumstances where the phone could go to sleep without calling allowSleepAgain() after a call to keepAwake()? The process that I am trying to control is transferring photos to a web service. If the phone sleeps, the app stops and the transfer stops. Some of users are not realising this and wondering why their photos don't get uploaded. The process is running in the back ground. I console.log out a message showing a call to keepAwake() and also for allowSleepAgain() and I'm only calling these methods in one place. I don't see allowSleepAgain() until the transfer has finished but if I try and transfer a large number of photos, the phone sleeps after 2 minutes as normal.
This doesn't happen if I call the method as per your event in the index file.
I have no idea, perhaps it's best to add bits of uploading logic to my example and figure out when it breaks...
Trying this on an iPad mini iOS v8.2 and it doesn't seem to have any effect. The device still locks after 2 minutes
Code as below. KeepPhoneAwake() is called first. The app transfers a number of photos. SetPhoneSleepTimeout() is called after the first file transfer. AllowPhoneToSleep() is called when all file transfers are completed or by the delayed timeout function after the set time period. Monitoring the console, I don't see the AllowPhoneToSleep() message but the device locks anyway. Android devices seem to work as expected.