title: How do I start playing audio when in silent mode & locked in iOS 6?
body: <h2>End-user process</h2>
  
  <ol>
  <li>Open app</li>
  <li>Switch on 'Silent Mode'.</li>
  <li>Press 'Lock-button'</li>
  <li>App can still START playing a sound after hours have passed, not playing any audio in the interim.</li>
  </ol>
  
  <h2>Apps that do this</h2>
  
  <p>A lot of alarm apps have manage to do this &amp; I dont think they are using silent audio to keep the app running as they do not sound if you actually exit the app with home. </p>
  
  <ul>
  <li>Alarm Clock Pro</li>
  <li>My Clock</li>
  <li>Wave Alarm</li>
  <li>Alarmed</li>
  <li>iHome</li>
  <li>...</li>
  </ul>
  
  <p>...Are they keeping a loop running after being locked some how or it a notification(which cant play sound in silent) starting the app back up to play the audio, or some other method?</p>
  
  <h2>Current Methods Implemented</h2>
  
  <p>AVAudioPlayer using:</p>
  
  <pre><code>AudioSessionInitialize(nil, nil, nil, nil);
  AudioSessionSetActive(YES);
  
  UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
  AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof(sessionCategory),&amp;sessionCategory);
  </code></pre>
  
  <p>And setting Info.plist to:</p>
  
  <p>Required background modes(UIBackGroundModes) - App plays audio (audio)</p>
  
  <h2>At Present</h2>
  
  <p>I can play audio even in silent when the app is running and on screen. If the audio is already running the app can be closed with home button and audio will run. BUT if the app is not playing audio, and the screen is locked, all threads are killed and audio is never played. How do theses apps manage to work around this?</p>
  
  <h2><strong>Possible approaches Found So Far</strong></h2>
  
  <p><strong>A. Use 'beginBackgroundTaskWithExpirationHandler:' with an infinite loop to keep app running indefinitely.</strong> </p>
  
  <p><strong>Pros:</strong></p>
  
  <ul>
  <li>Looks like you can make this work in a lot of situations, even when the user presses home.</li>
  </ul>
  
  <p><strong>Cons:</strong></p>
  
  <ul>
  <li>This goes against apple policies as far as I can tell. </li>
  <li>will use more resources</li>
  </ul>
  
  <p><strong>Comments:</strong></p>
  
  <p>I've almost got this to work and might with some tweaking. This does not seem to be what all these other alarms are doing as they do not keep on running if you press home BTN. Which suggest that they use some method that gives them permission to run while locked but not in the BG. (Which is what I need)</p>
  
  <p>Also, When you ask how much time you have left running you get aprox 10 min. By dropping an infinite loop in there the numbers will actually run down to 0 and then go into the negatives for hours on end.(tested) Im not sure how this would behave in the real world or in terms of app acceptance. </p>
  
  <p><strong>B. Use a silent audio loop to pose as a continus audio playing media center</strong></p>
  
  <p><strong>Pros:</strong></p>
  
  <ul>
  <li>Worked when locked, and will keep up running in most situations.</li>
  </ul>
  
  <p><strong>Cons:</strong></p>
  
  <ul>
  <li>Can fail if interrupted by another media center and in some other occasions.</li>
  <li>Can also go agains apple policy.</li>
  </ul>
  
  <p><strong>Comments:</strong></p>
  
  <p>This can work I a lot of situations but is by far not ideal. And since Like I say again, there has to be another method that is not documented. </p>
  
  <h2>Conclussions Thus Far</h2>
  
  <p>Testing with the listed APPs suggests that they are not using any of the two methods I just described. Method 'A' seems to be closer but if implemented would not behave how these apps behave. </p>
  
  <p>I used a apple developer ticket to get more info, I'll post any new findings along those means as well. </p>
  
  <h2>Thank You</h2>
  
  <p>Any insight is appreciated, and for your participation thus far.</p>