0

I'm building a web application that will be used on mobile and desktop, and after testing on iOS, I've noticed that my phone will go into an idle state (screen turns off, presented with lock screen on return) even if there is a file being uploaded (ajax upload). Is there any way to prevent this from happening?

I'm testing the app by running it as a 'home-screened' web app (ie. a website you've saved to the home screen) if that makes a difference.

machinemessiah
  • 424
  • 1
  • 5
  • 14

1 Answers1

2

Originally I couldn't find an answer to this (most likely due to my particular phrasing of the question), but I ended up adding the following to my upload modal which prevented my phone from sleeping while the modal was open (only tested on iOS7):

<div style="display:none">
   <audio id="prevent_sleep" style="display:none" src="prevent_sleep.mp3" onended="this.play();" controls loop autobuffer autoplay></audio>
</div>
//prevent_sleep.mp3 is a 10 second silent mp3 file

<script>
   window.onload = function() {
      var audioEl = document.getElementById("prevent_sleep");

      audioEl.load();
      audioEl.play();
   };
</script>

Which I found at http://flax.ie/how-to-get-hidden-autoplaying-audio-in-html5-on-ios/

machinemessiah
  • 424
  • 1
  • 5
  • 14