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买脚... 透视透视挂!wepoker买脚本靠谱吗,wepoker免费脚本弱密码(详细辅助器免费)1、每一步都需...
透视有挂!aapoker真的假... 透视有挂!aapoker真的假的(透视)aa poker辅助,必胜教程(有挂插件);1、这是跨平台的...
透视神器!有没有人wepoke... 透视神器!有没有人wepoker,wepoker脚本(详细挂);有没有人wepoker辅助器中分为三...
透视工具!aapoker脚本(... 透视工具!aapoker脚本(透视)aapoker脚本,科技教程(有挂技巧)进入游戏-大厅左侧-新手...
透视能赢!wepoker安装教... 透视能赢!wepoker安装教程,we-poker辅助器(详细可以设置透视);1、wepoker安装...
透视app!aapoker怎么... 透视app!aapoker怎么设置抽水(透视)aapoker怎么提高中牌率,扑克教程(有挂技巧)透视...
透视工具!aapoker真的假... 透视工具!aapoker真的假的(透视)aapoker怎么提高中牌率,新2025版(有挂解密)1、操...
透视规律!wejoker黑侠辅... 透视规律!wejoker黑侠辅助器,wepoker代打辅助(详细破解器)1、用户打开应用后不用登录就...
辅助透视!aapoker怎么设... 辅助透视!aapoker怎么设置抽水(透视)aapoker插件,辅助教程(有挂方法)aapoker怎...
透视脚本!wepoker透视脚... 透视脚本!wepoker透视脚本,wepoker有透视吗(详细辅助器安装包);1、wepoker有透...