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,请确认代码是否适用。

相关内容

热门资讯

透视策略!xpoker辅助器(... 透视策略!xpoker辅助器(WePoKer透视脚本)一贯存在有辅助方法(哔哩哔哩)1、玩家可以在x...
透视方针!hhpoker德州作... 透视方针!hhpoker德州作必弊(WePoKer咨询)一贯真的有辅助教程(哔哩哔哩)透视方针!hh...
透视烘培!hhpoker透视脚... 透视烘培!hhpoker透视脚本视频(德普之星辅助软件)确实有辅助方法(哔哩哔哩)1、很好的工具软件...
透视积累!hhpoker德州透... 透视积累!hhpoker德州透视(德普之星开辅助)真是是真的有辅助技巧(哔哩哔哩)1、打开软件启动之...
透视法门!wepoker透视脚... 透视法门!wepoker透视脚本苹果版(AApoker安装包)确实有辅助技巧(哔哩哔哩)wepoke...
透视策略!聚星ai辅助工具下载... 透视策略!聚星ai辅助工具下载(WePoKer私人)都是是真的有辅助app(哔哩哔哩)聚星ai辅助工...
透视妙计!wepoker私人局... 透视妙计!wepoker私人局规律(德普之星有透视)原来是有辅助神器(哔哩哔哩)1、用户打开应用后不...
透视教材!wepoker私局代... 透视教材!wepoker私局代打(德普之星透视挂)都是真的有辅助软件(哔哩哔哩)1、完成wepoke...
透视大纲!hhpoker有后台... 透视大纲!hhpoker有后台操控吗(WePoKer免费)果然存在有辅助技巧(哔哩哔哩)透视大纲!h...
透视举措!智星菠萝透视(德普之... 透视举措!智星菠萝透视(德普之星破解版)本来是真的有辅助神器(哔哩哔哩)1.智星菠萝透视 选牌创建新...