title: How to let AVPlayer retrieve playlist secured by SSL?
body: <p>We´re developing a HTTP-streaming iOS app that requires us to receive playlists from a secured site. This site requires us to authenticate using a self signed SSL certificate.</p>
  
  <p>We read the credentials from a .p12 file before we use NSURLConnection with a delegate to react to the authorization challenge. </p>
  
  <pre><code>- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
  {
      [[challenge sender] useCredential:  self.credentials forAuthenticationChallenge:challenge];
  }
  
  - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
  {
      return YES;
  }
  </code></pre>
  
  <p>By doing this initial connection to the URL where we´re getting the .m3u8 playlist we´re able to play back the playlist using AVPlayer. The problem is that this method only works in the simulator.</p>
  
  <p>NOTE: We´re able to download the playlist using the NSURLConnection on device. This must mean that the AVPlayer somehow can´t continue using the trust established during this initial connection.</p>
  
  <p>We have also tried adding the credentials to the [NSURLCredentialStorage sharedCredentialStorage] without any luck.</p>
  
  <p>Below follows our shotgun approach for that:</p>
  
  <pre><code>NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc]
                                           initWithHost:host
                                           port:443
                                           protocol:@"https"
                                           realm:nil
                                           authenticationMethod:NSURLAuthenticationMethodClientCertificate];
  
  
  
  [[NSURLCredentialStorage sharedCredentialStorage] setDefaultCredential:creds
                                                      forProtectionSpace:protectionSpace];
  
      NSURLProtectionSpace *protectionSpace2 = [[NSURLProtectionSpace alloc]
                                           initWithHost:host
                                           port:443
                                           protocol:@"https"
                                           realm:nil
                                           authenticationMethod:NSURLAuthenticationMethodServerTrust];
  
  
  
  [[NSURLCredentialStorage sharedCredentialStorage] setDefaultCredential:creds
                                                      forProtectionSpace:protectionSpace2];
  </code></pre>
  
  <p>EDIT: According to <a href="https://stackoverflow.com/questions/4164846/nsurlcredentialstorage-and-client-certificate-authentication">this question</a>: the above method doesn´t work with certificates.</p>
  
  <p>Any hint to why it doesn´t work on device, or an alternate solution is welcome!</p>