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

相关内容

热门资讯

透视科技!红龙poker辅助工... 透视科技!红龙poker辅助工具(透视)竟然真的有挂(详细辅助可靠教程)1、红龙poker辅助透视辅...
透视ai代打!aapoker辅... 透视ai代打!aapoker辅助插件工具(透视)原来真的是有挂(详细辅助必备教程)1)aapoker...
透视模拟器!wepoker有人... 透视模拟器!wepoker有人用过吗(透视)真是有挂(详细辅助2025新版教程)1、每一步都需要思考...
透视计算!pokermaste... 透视计算!pokermaster破解版(透视)一直是有挂(详细辅助必胜教程)1、玩家可以在软件透明挂...
透视教程!wepoker破解器... 透视教程!wepoker破解器激活码(透视)一直真的是有挂(详细辅助攻略教程)1)辅助挂:进一步探索...
透视ai代打!wepoker买... 透视ai代打!wepoker买钻石有用吗(透视)切实是有挂(详细辅助2025新版)1、起透看视 透明...
透视代打!wepoker透视脚... 透视代打!wepoker透视脚本免费下载(透视)果然是真的有挂(详细辅助必胜教程);1、wepoke...
透视攻略!hhpoker的辅助... 透视攻略!hhpoker的辅助是真的吗(透视)其实是有挂(详细辅助新版2025教程)1、完成透视辅助...
透视攻略!wepoker透视脚... 透视攻略!wepoker透视脚本免费下载pc(透视)竟然存在有挂(详细辅助教你攻略);1)wepok...
透视插件!聚星ai辅助工具下载... 透视插件!聚星ai辅助工具下载(透视)原来真的有挂(详细辅助揭秘教程);辅助器中分为三种模型:软件透...