title: Ionic prevent phone sleeping only when app is running
body: <p>The <a href="https://github.com/EddyVerbruggen/Insomnia-PhoneGap-Plugin/tree/47ba15a4ad791eb4d5a0643cdb7ef69f73109e15" rel="nofollow noreferrer">Insomnia</a> plugin promises to keep devices awake with <code>window.plugins.insomnia.keepAwake()</code>, until such time as <code>window.plugins.insomnia.allowSleepAgain()</code> is called.</p>
  
  <p>But for some apps it only makes sense for the device to stay awake while the app is active. If the user pauses the app and forgets they have left it going in the background, it would be nice to allow sleep rather than decimate their battery level.</p>
  
  <p>Typically actions required on app pause are handled through the <code>pause</code> event:</p>
  
  <pre><code>function onDeviceReady() {
      document.addEventListener("pause", onPause, false);
  }
  
  function onPause() {
      window.plugins.insomnia.allowSleepAgain();
  }
  </code></pre>
  
  <p>But according to <a href="http://cordova.apache.org/docs/en/3.5.0/cordova/events/events.pause.html" rel="nofollow noreferrer">Cordova docs</a>, the Pause handler on iOS can't call anything native - which would include the Insomnia plugin.</p>
  
  <p>How to achieve the desired functionality?</p>