EddyVerbruggen / Insomnia-PhoneGap-Plugin

:sleepy: Prevent the screen of the mobile device from falling asleep

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't make it work

Danpelle opened this issue · comments

I'm developing an app using Cordova, and the Insomnia plugin is perfect for what I need. But I can't make it work. To make everything as simple as possible, I created a new Cordova project, installed the plugin automatically (using the CLI) and add the following lines in the original Cordova index.html file to call the KeepAwake command:

`<script type="text/javascript" src="js/Insomnia.js"></script>

<script> window.plugins.insomnia.keepAwake() </script>`

I have tried to call the Insomnia plugin into the device-ready call function, but it also didn't work.
Here is the code:

`<script>
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}

// Cordova is loaded and it is now safe to make calls Cordova methods
//

function onDeviceReady() {
window.plugins.insomnia.keepAwake()
</script>`

The phone still auto-lock after 30s. I'm using an iPhone 5s running iOS 10.3.3 and Cordova iOS version 4.4.0.

What's wrong???

Thank you very much!

I'm having the exact same issue as above.

Just to let you know I tried everything but could on get this working on a button. I did however get it working using the onLoad Function in the <body> tags. Give that a go.

<body onLoad="window.plugins.insomnia.keepAwake()">

Has same problem. But body and button tags don't work too ((((.

Using: iPhone 5s, iOS 12.2, PhoneGap ios engine 4.5.5, Insomnia 4.3.0 via PhoneGap build.

@zjbennett:
Can you provide more info? May be full html file?

I also need the plugin to load when the app is opened, not who clicks the button. Any solution?

I win!

<script type="text/javascript" charset="utf-8"> function onLoad() { document.addEventListener("deviceready", onDeviceReady, false); } function onDeviceReady() { window.plugins.insomnia.keepAwake(); } </script>

This code works for me.