3

私はApple Media Playback Programming Guideの例に従っています。

次のコードは iOS 11 では機能しますが、iOS 10 ではクラッシュします。

ダウンロードを次のようにセットアップします。

func setupAssetDownload(for item: DownloadItem) {
    let url = URL(string: item.urlVideo!)!
    let asset = AVURLAsset(url: url)

    // Create new AVAssetDownloadTask for the desired asset
    guard let task = downloadSession.makeAssetDownloadTask(asset: asset,
                                                           assetTitle: item.title!,
                                                           assetArtworkData: nil,
                                                           options: [AVAssetDownloadTaskMinimumRequiredMediaBitrateKey: 265_000])
        else { return }

    // Start task and begin download
    task.resume()
}

ここで失敗します:

func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
    /*
     This is the ideal place to begin downloading additional media selections
     once the asset itself has finished downloading.
     */
    if let error = error as NSError? {
        switch (error.domain, error.code) {
        case (NSURLErrorDomain, NSURLErrorCancelled):
            /*
             This task was canceled, you should perform cleanup using the
             URL saved from AVAssetDownloadDelegate.urlSession(_:assetDownloadTask:didFinishDownloadingTo:).
             */
            ...

        case (NSURLErrorDomain, NSURLErrorUnknown):
            fatalError("Downloading HLS streams is not supported in the simulator.")

        default:
            fatalError("An unexpected error occured \n\(error.code) - \(error.domain) - \(error.localizedDescription)")
        }
    } else {
        // downloaded
    }
}

次のエラーが表示されます。

Error Domain=AVFoundationErrorDomain 
Code=-11800 \"The operation could not be completed\" 
UserInfo={
    NSLocalizedDescription=The operation could not be completed,
    NSLocalizedFailureReason=An unknown error occurred (-12780)
}

誰かがこれを解決する方法を教えてもらえますか?

注: を作成するfileURLWithPath代わりに使用することについて読んだことがありますが、まったく機能しませんでした。stringURL

NSAppTransportSecurity とは関係ありません。

4

0 に答える 0