title: How to fix audio play() in React for iOS?
body: <p>I am making a timer app in React. Whenever the timer counts back to 0 it should play a wav sound file. It works fine on IE, Chrome, Edge, Android, but not on iOS.</p>
  
  <p>I have found an explanation why this is happening, but not how to work around it.</p>
  
  <blockquote>
    <p>In Safari on iOS (for all devices, including iPad), where the user may be on a cellular network and be charged per data unit, preload and autoplay are disabled. No data is loaded until the user initiates it. This means the JavaScript play() and load() methods are also inactive until the user initiates playback, unless the play() or load() method is triggered by user action. In other words, a user-initiated Play button works, but an onLoad="play()" event does not. (<a href="https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html" rel="nofollow noreferrer">Source: Apple Developer</a>)</p>
  </blockquote>
  
  <pre><code> &lt;audio id="beep" src="http://www.pacdv.com/sounds/interface_sound_effects/sound106.wav"&gt;&lt;/audio&gt;
  
   startTimer = () =&gt; {
        document.getElementById('beep').play();
   }
  </code></pre>
  
  <p>The start timer function runs when the timer reaches 0, not on a click event. Expected result would be on iOS to play the audio when counts back to 0.</p>