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

相关内容

热门资讯

透视讲解!微乐小程序免费黑科技... 透视讲解!微乐小程序免费黑科技,微乐小程序修复系统有用吗(透视)果然真的有挂(哔哩哔哩)1、进入到微...
第4分钟安装!微乐小程序免费黑... 第4分钟安装!微乐小程序免费黑科技,微乐小程序辅助器代理(开挂)好像是有挂(2026)微乐小程序免费...
此事迅速冲上热搜!微乐小程序免... 此事迅速冲上热搜!微乐小程序免费黑科技,2025微乐小程序黑科技(透视)一贯真的是有挂(哔哩哔哩)1...
第一分钟下载!微乐小程序黑科技... 第一分钟下载!微乐小程序黑科技,微乐微信小程序辅助软件(开挂)总是真的是有挂(2026)1、全新机制...
透视教学!微乐小程序免费黑科技... 透视教学!微乐小程序免费黑科技,微乐锄大地脚本(透视)其实是真的挂(哔哩哔哩)1)微乐小程序免费黑科...
3分钟透视!微乐小程序免费黑科... 3分钟透视!微乐小程序免费黑科技,微乐贵阳捉鸡麻将辅助(开挂)总是真的有挂(2026)微乐小程序免费...
值得注意的是!微乐小程序免费黑... 值得注意的是!微乐小程序免费黑科技,微乐小程序挂哪里有(透视)其实有挂(哔哩哔哩)1、每一步都需要思...
第7分钟辅助!微乐小程序免费黑... 第7分钟辅助!微乐小程序免费黑科技,微乐广西小程序插件(开挂)总是真的有挂(2026)微乐小程序免费...
透视安卓版!微乐小程序免费黑科... 透视安卓版!微乐小程序免费黑科技,微乐自建房脚本免费下载入口(透视)切实是真的挂(哔哩哔哩)一、微乐...
第9分钟神器!微乐小程序免费黑... 第9分钟神器!微乐小程序免费黑科技,微乐小程序授权(开挂)总是存在有挂(2026)微乐小程序免费黑科...