AVAssetDownloadURLSession从未初始化
创始人
2024-11-12 20:00:22
0

在创建AVAssetDownloadURLSession之前,需要在AppDelegate中设置NSURLSessionConfiguration并创建URLSession。以下是示例代码:

在AppDelegate中:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { let backgroundConfiguration = URLSessionConfiguration.background(withIdentifier: "yourIdentifer") backgroundConfiguration.sessionSendsLaunchEvents = true

let downloadSession = URLSession(configuration: backgroundConfiguration, delegate: self, delegateQueue: OperationQueue.main)
downloadSession.getTasksWithCompletionHandler { (dataTasks, uploadTasks, downloadTasks) in
    for downloadTask in downloadTasks {
        downloadTask.cancel()
    }
}
downloadSession.finishTasksAndInvalidate()
return true

}

在ViewController中:

let urlAsset = AVURLAsset(url: videoURL) let downloadTask = downloadSession.makeAssetDownloadTask(asset: urlAsset, assetTitle: "title", assetArtworkData: nil, options: nil) downloadTask?.resume()

注意:此代码在Swift 5.0上测试通过。如果使用的是其他版本的Swift,请确认代码是否适用。

相关内容

热门资讯

wepoker的辅助器!wep... wepoker的辅助器!wepokerplus透视(透视)插件-切实透视有挂wepoker的辅助器辅...
wepoker透视有用吗!we... wepoker透视有用吗!we poker插件(透视)攻略-果然关于真的是有挂1、上手简单,内置详细...
德普之星app安卓版破解版!w... 德普之星app安卓版破解版!wepoker免费脚本咨询(透视)攻略-确实解迷真的是有挂德普之星app...
wepoker免费脚本咨询!h... wepoker免费脚本咨询!hhpoker德州挂真的有吗(透视)方法-都是推荐有挂小薇(辅助器软件下...
pokeplus脚本!德州局透... pokeplus脚本!德州局透视(透视)神器-真是了解真的有挂1)德州局透视免费钻石:进一步探索德州...
wepoker买钻石有用吗!w... wepoker买钻石有用吗!wpk私人局有透视吗(透视)工具-好像科普真的是有挂1、起透看视 wep...
wepoker怎么设置透视!德... wepoker怎么设置透视!德普之星app安卓版破解版(透视)教程-总是总结真的有挂1、不需要AI权...
wepoker养号规律!大菠萝... wepoker养号规律!大菠萝手游辅助(透视)方法-原来必备是真的挂1、用户打开应用后不用登录就可以...
哈糖大菠萝怎么挂!wepoke... 哈糖大菠萝怎么挂!wepoker有透视底牌吗(透视)挂-一贯辅助真的是有挂;1、金币登录送、破产送、...
wepokerplus透视!w... wepokerplus透视!wepoker私人局透视教程(透视)插件-好像解迷有挂1、下载好wepo...