title: AVCaptureSession failing on first initialization
body: <p>I have a view in my app that initializes an instance of AVCaptureSession, with a video preview on screen, and begins a recording when a button is pressed. On iPad it works fine, but on an iPhone it would occasionally fail to load the capture session; there wouldn't be a video preview, and if the button to record was pressed, it would skip the recording and immediately execute the</p>
  
  <pre><code>- (void)captureOutput:(AVCaptureFileOutput *)captureOutput
  didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL
    fromConnections:(NSArray *)connections
              error:(NSError *)error
  </code></pre>
  
  <p>method. With one of the recent iOS updates there was an issue with the audio capture, which I fixed by adding</p>
  
  <pre><code>AVAudioSession *audioSession = [AVAudioSession sharedInstance];
  [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
  [audioSession setActive:YES error:nil];
  </code></pre>
  
  <p>to the audio session setup. Since I've done that though, the capture session loading issue on the iPhone has become consistent. On app launch, the first attempt to load the view will always fail, and Xcode gives me this output:</p>
  
  <pre><code>_serverConnectionDiedNotification. Info -- notification=Error
  Domain=AVFoundationErrorDomain Code=-11819 "Cannot Complete Action" 
  UserInfo=0x14679150 {NSLocalizedRecoverySuggestion=Try again later.,
  NSLocalizedDescription=Cannot Complete Action},
  AVPlayer = &lt;MPQueuePlayer: 0x1458aa80&gt;, currentTime = nan
  </code></pre>
  
  <p>If I go back to the menu from that view, and then try to load the view again, every subsequent attempt to load it is successful; it's just the first attempt to load the view that fails. I looked up the error code but it was a fairly nonspecific "AVErrorMediaServicesWereReset", which doesn't tell me much. I've seen this error code thrown up for other problems in my search for answers, but nothing for my specific problem. I assume it has something to do with the audio since it became consistent once I changed that, but I'm not sure what I can do about that.</p>