大佬教程收集整理的这篇文章主要介绍了ios – 如何让AVPlayer检索由SSL保护的播放列表?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在我们将NSURLConnection与委托一起使用以响应授权质询之前,我们从.p12文件中读取凭据.
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { [[challenge sender] useCredential: self.credentials forAuthenticationChallenge:challenge]; } - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace { return YES; }
通过初始连接到我们获取.m3u8播放列表的URL,我们可以使用AVPlayer播放播放列表.问题是这种方法只适用于模拟器.
注意:我们可以使用设备上的NSURLConnection下载播放列表.这必然意味着AVPlayer不能继续使用在此初始连接期间建立的信任.
我们还尝试将凭据添加到[NSURLCredentialStorage sharedCredentialStorage],但没有任何运气.
下面是我们的霰弹枪方法:
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];
编辑:根据this question:上述方法不适用于证书.
请在下面找到示例代码.
// AVURLAsset + Loader AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:url options:nil]; AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset]; AVAssetResourceLoader *loader = asset.resourceLoader; [loader setDelegate:self queue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0)]; // AVPlayer AVPlayer *avPlayer = [AVPlayer playerWithPlayerItem:playerItem];
您将需要处理resourceLoader:shouldWaitForLoadingOfRequestedResource:delegate方法,该方法将在需要身份验证时调用,您可以使用NSURLConnection来请求安全资源.
(BOOL)resourceLoader:(AVAssetResourceLoader *)resourceLoader shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest { //Handle NSURLConnection to the SSL secured resource here return YES; }
希望这可以帮助!
P.S:使用CocoaHTTPServer的代理方法运行良好,但使用AVAssetResourceLoader是一种更优雅的解决方案.
以上是大佬教程为你收集整理的ios – 如何让AVPlayer检索由SSL保护的播放列表?全部内容,希望文章能够帮你解决ios – 如何让AVPlayer检索由SSL保护的播放列表?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。