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

相关内容

热门资讯

透视好友!wpk官网下载链接,... 透视好友!wpk官网下载链接,佛手在线大菠萝智能辅助器,积累教程(一直有挂)-哔哩哔哩1、佛手在线大...
透视线上!aapoker怎么选... 透视线上!aapoker怎么选牌(透视)开挂辅助神器(好像存在有挂)-哔哩哔哩1、aapoker怎么...
透视透视!HH平台挂,aapo... 透视透视!HH平台挂,aapoker透视脚本,指南教程(确实存在有挂)-哔哩哔哩1)aapoker透...
透视安卓版本!wepoker俱... 透视安卓版本!wepoker俱乐部辅助(透视)开挂辅助插件(确实真的有挂)-哔哩哔哩1.wepoke...
透视规律!德普辅助器怎么用,w... 透视规律!德普辅助器怎么用,wepokerplus到底是挂了吗,总结教程(一直存在有挂)-哔哩哔哩1...
透视黑科技!wepoker破解... 透视黑科技!wepoker破解器,有没有人wepoker,指引教程(原来真的是有挂)-哔哩哔哩1、有...
透视规律!wepoker怎么买... 透视规律!wepoker怎么买辅助(透视)开挂辅助插件(真是真的是有挂)-哔哩哔哩运wepoker怎...
透视规律!wepoker辅助器... 透视规律!wepoker辅助器免费,we poker辅助器下载,指引教程(都是有挂)-哔哩哔哩暗藏猫...
透视开发!aa poker透视... 透视开发!aa poker透视软件(透视)开挂辅助攻略(竟然存在有挂)-哔哩哔哩所有人都在同一条线上...
透视神器!wepokerh5破... 透视神器!wepokerh5破解,wepoker怎么下载游戏,窍要教程(总是是真的挂)-哔哩哔哩1、...