2

クライアント アプリ用のオフライン フェアプレイ コンテンツを作成しています。HLSCatalog デモ アプリの Apple サンプル ダウンロード マネージャー AssetPersistenceManager クラスを参照して、その機能を実装しました。ここで強調したいのは、AssetPersistenceManager クラスに 1 つの関数と 2 つのコールバックです。

    /
    func downloadStream(for asset: Asset) {
        /
         For the initial download, we ask the URLSession for an AVAssetDownloadTask
         with a minimum bitrate corresponding with one of the lower bitrate variants
         in the asset.
         */
        guard let task = assetDownloadURLSession.makeAssetDownloadTask(asset: asset.urlAsset, assetTitle: asset.name, assetArtworkData: nil, options: [AVAssetDownloadTaskMinimumRequiredMediaBitrateKey: 265000]) else { return }

        /
        task.taskDescription = asset.name

        activeDownloadsMap[task] = asset

        task.resume()

        var userInfo = [String: Any]()
        userInfo[Asset.Keys.name] = asset.name
        userInfo[Asset.Keys.downloadState] = Asset.DownloadState.downloading.rawValue

        NotificationCenter.default.post(name: AssetDownloadStateChangedNotification, object: nil, userInfo:  userInfo)
    }

ストリームのダウンロードが完了したらコールバックします

func urlSession(_ session: URLSession, assetDownloadTask: AVAssetDownloadTask, didFinishDownloadingTo location: URL) {
    let userDefaults = UserDefaults.standard

    /
     This delegate callback should only be used to save the location URL
     somewhere in your application. Any additional work should be done in
     `URLSessionTaskDelegate.urlSession(_:task:didCompleteWithError:)`.
     */
    if let asset = activeDownloadsMap[assetDownloadTask] {

        userDefaults.set(location.relativePath, forKey: asset.name)
    }
}

最後は didCompleteWithError コールバックです

func urlSession(_ session: URLSession, task: URLSessionTask,
didCompleteWithError error: Error?)

iOS < 10.2 ではすべて正常に動作するようですが、最新の iOS 10.2 を実行している一部のデバイスでテストした後、アプリは常に didFinishDownloadTo デリゲートへのコールバックを取得しましたが、完了率は 13 ~ 15% のみでした。その後、didCompleteWithError が呼び出され、以下のエラーを受け取りました。

> "=======> completed percent 11.2888760669556" .
> "=======> completed percent 11.44566601233" 
> "=======> completed percent 11.7592459030787"
> "=======> completed percent 12.0728257938275" 
> "=======> completed percent 12.5431956299506" 
> "=======> completed percent 13.0135654660738" 
> "=======> completed percent 13.3271453568226" 
> "=======> completed percent 13.6407252475713" 
> "=======> completed percent 13.9543051383201" 
> "=======> completed percent 14.1110950836945" 
> "=======> completed percent 14.2678850290689" 
> "Error Domain=AVFoundationErrorDomain Code=-11800 \"The operation could not
> be completed\" UserInfo={NSLocalizedDescription=The operation could
> not be completed, NSLocalizedFailureReason=An unknown error occurred
> (-12667)}"

プロキシデバッグアプリで確認すると、アプリが応答全体を受信する前に接続を閉じることが指摘されています。

Status
Complete
Failure
Client closed connection before receiving entire response
Response Code
206 Partial Content

そのエラーが発生するのは iOS 10.2 のみです。そのバージョンより下の他の OS でテストされた同じストリームは、引き続き正常に動作します。この部分についてiOS 10.2の変更ログを見つけようとしましたが、何も見つかりませんでしたか? 何かアドバイスはありますか?

4

1 に答える 1