title: Start playing sound in background on iOS?
body: <p>I'm trying to do something similar to <a href="https://www.thetileapp.com" rel="nofollow noreferrer">Tile.app</a>. When it shows a notification, it plays a sound. That seems simple enough-- use <code>UILocalNotification</code> and include the sound file name. But local notifications limit sounds to no more than 30 seconds, and Tile's sound keeps playing for a whole lot longer than that. I expect it's looping, and it continues until I can't stand the noise any more.</p>
  
  <p>The sound also plays even if the phone's mute switch is on, which doesn't happen with local notifications. For these reasons, <code>UILocalNotification</code> appears to be out.</p>
  
  <p>I thought maybe I could post a text-only local notification and have my app play the sound. But using <code>AVAudioPlayer</code>, the <code>play</code> method returns <code>NO</code> and the sound doesn't play.</p>
  
  <p><a href="https://stackoverflow.com/questions/16564298/avaudioplayer-doesnt-start-playing-in-background">Other questions</a> have suggested that this is by design, that apps aren't supposed to be able to play sounds from the background-- only continue sound that's already playing. I'd accept that reasoning except that Tile does it, so it's obviously possible. One <a href="https://stackoverflow.com/questions/20421698/start-playing-audio-from-a-background-task-via-avaudioplayer-in-xcode">suggested workaround</a> violates Apple's guidelines in a way that I'm pretty sure Apple checks for now.</p>
  
  <p>Some details that may be relevant:</p>
  
  <ul>
  <li>I have the <code>audio</code> background mode in Info.plist</li>
  <li>I use <code>AVAudioSessionCategoryPlayback</code> on the audio session, and the session should be active (at least, <code>setActive:error:</code> claims to succeed).</li>
  <li>This app uses Bluetooth but does not currently use the <code>bluetooth-central</code> background mode.</li>
  </ul>