Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在Swift 3中具有客户端证书的AVPlayer_Ios_Swift_Ssl_Avplayer_Tvos - Fatal编程技术网

Ios 在Swift 3中具有客户端证书的AVPlayer

Ios 在Swift 3中具有客户端证书的AVPlayer,ios,swift,ssl,avplayer,tvos,Ios,Swift,Ssl,Avplayer,Tvos,我想通过我的代理播放stream,在那里应用我的客户端证书。但没有一个事件在委托中处理。当我在流媒体服务器端关闭客户端证书时,播放工作正常。否则-400错误请求(客户端不发送客户端证书)。我尝试在委托的身份验证质询中发送证书,但未处理此事件 (tvOS 10和swift 3) 以下是初始化播放的代码: let movieAsset:AVURLAsset = AVURLAsset(url: plurl!, options: nil) let plCont:PlayerViewDelegate =

我想通过我的代理播放stream,在那里应用我的客户端证书。但没有一个事件在委托中处理。当我在流媒体服务器端关闭客户端证书时,播放工作正常。否则-400错误请求(客户端不发送客户端证书)。我尝试在委托的身份验证质询中发送证书,但未处理此事件

(tvOS 10和swift 3)

以下是初始化播放的代码:

let movieAsset:AVURLAsset = AVURLAsset(url: plurl!, options: nil)
let plCont:PlayerViewDelegate = PlayerViewDelegate()

movieAsset.resourceLoader.setDelegate(plCont, queue: DispatchQueue.main)

let playerItem:AVPlayerItem = AVPlayerItem(asset: movieAsset)

playerController.player = AVPlayer(playerItem: playerItem)
playerController.player?.play()
下面是描述委托的代码:

    class PlayerViewDelegate: NSObject, AVAssetResourceLoaderDelegate {

        func resourceLoader(_ resourceLoader: AVAssetResourceLoader, shouldWaitForLoadingOfRequestedResource loadingRequest: AVAssetResourceLoadingRequest) -> Bool{
            return true
        }

        func resourceLoader(_ resourceLoader: AVAssetResourceLoader, shouldWaitForRenewalOfRequestedResource renewalRequest: AVAssetResourceRenewalRequest) -> Bool{
            return true
        }

        func resourceLoader(_ resourceLoader: AVAssetResourceLoader, didCancel loadingRequest: AVAssetResourceLoadingRequest){

        }

        func resourceLoader(_ resourceLoader: AVAssetResourceLoader, didCancel authenticationChallenge: URLAuthenticationChallenge){
            print("PLAY CHALLENGE 2")
        }

        func resourceLoader(_ resourceLoader: AVAssetResourceLoader, shouldWaitForResponseTo authenticationChallenge: URLAuthenticationChallenge) -> Bool {
            print("PLAY CHALLENGE")
            return true
        }
}
“游戏挑战”(以及所有其他事件)从未发生过

我做错了什么

更新

我看到了这个话题

当我将方案更改为自定义方案:https->ss_https时,只调用了一个方法:

func resourceLoader(_ resourceLoader: AVAssetResourceLoader, shouldWaitForLoadingOfRequestedResource loadingRequest: AVAssetResourceLoadingRequest) -> Bool

但我需要将方案更改回原来的方案,因为其他事件仍然没有处理。互联网上的所有示例都是用objective-c编写的,只需使用request.scheme=“https”更改方案即可。但是在swift 3中,所有重要的对象都是不可变的!因此,我无法在resourceLoader事件中更改请求、url、方案等

您正在使用HTTP/HTTPs吗?如果AVURLAsset的url使用http或https url方案,您的代理将永远不会有机会处理加载请求。为了让资源加载器使用您的委托,必须使用具有自定义方案的url初始化AVURLASET。签出URL操作部分,可能重复:是的,我看到了这篇文章。但我仍然有一个问题“如何将客户端证书发送到服务器”。我会更新这个问题。@Chris,现在我无法将我的url方案更改回原来的url方案,正如在许多类似于您发布的问题的评论中所描述的那样。进度!我很高兴你们的代表现在被召集起来
AVAssetResourceLoadingRequest
对象包含原始请求以及重建新请求所需的所有信息。使用原始请求获取URL并删除/替换方案。