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

相关内容

热门资讯

透视资料!智星德州辅助译码插件... 透视资料!智星德州辅助译码插件靠谱吗(透视)pokemomo辅助工具(辅助)原来真的有方法(哔哩哔哩...
透视教程书!来玩app破解版(... 透视教程书!来玩app破解版(透视)sohoo竞技联盟辅助器(辅助)其实真的是有app(哔哩哔哩)1...
透视绝活儿!德州局怎么透视(透... 透视绝活儿!德州局怎么透视(透视)菠萝德州透视脚本(辅助)其实真的有攻略(哔哩哔哩)1、很好的工具软...
透视手册!聚星ai辅助工具收费... 透视手册!聚星ai辅助工具收费多少(透视)哈糖大菠萝免费辅助器(辅助)原来真的是有方法(哔哩哔哩)1...
透视模块!德州局透视脚本下载安... 透视模块!德州局透视脚本下载安装最新版本(透视)菠萝辅助器免费版的特点(辅助)都是一直都是有技巧(哔...
透视操作!werplan怎么作... 透视操作!werplan怎么作必弊(透视)werplan怎么作必弊(辅助)都是一直总是有攻略(哔哩哔...
透视阶段!werplan免费挂... 透视阶段!werplan免费挂下载(透视)poker world辅助器(辅助)一直有神器(哔哩哔哩)...
透视模块!pokemmo手机版... 透视模块!pokemmo手机版透视脚本(透视)pokemmo辅助器脚本下载(辅助)本来一直总是有攻略...
透视法门!拱趴大菠萝十三水作必... 透视法门!拱趴大菠萝十三水作必弊(透视)xpoker辅助工具(辅助)一直存在有神器(哔哩哔哩)1、拱...
透视秘籍!哈糖大菠萝软件下载(... 透视秘籍!哈糖大菠萝软件下载(透视)xpoker怎么作必弊(辅助)总是有神器(哔哩哔哩)1、每一步都...