Prevent idle state when uploading (web app on iOS)

自古美人都是妖i 提交于 2019-12-04 06:28:50

问题


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.


回答1:


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/



来源:https://stackoverflow.com/questions/19642026/prevent-idle-state-when-uploading-web-app-on-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!