AVAssetDownloadDelegate方法在后台没有被调用
创始人
2024-11-12 20:00:20
0

当应用程序运行在后台时,下载会在一个单独的进程中运行,因此AVAssetDownloadDelegate方法不会被自动调用。要解决这个问题,需要在调用startSession方法之前向assetDownloadTask对象添加一个后台URL会话配置,并在AppDelegate中设置会话委托。示例代码如下:

//获取后台下载的会话ID let backgroundConfiguration = URLSessionConfiguration.background(withIdentifier: "com.myapp.backgroundDownload")

//创建AVAssetDownloadURLSession对象 let assetDownloadURLSession = AVAssetDownloadURLSession(configuration: backgroundConfiguration, assetDownloadDelegate: self, delegateQueue: OperationQueue.main)

//创建assetDownloadTask对象 let assetDownloadTask = assetDownloadURLSession.makeAssetDownloadTask(asset: asset, assetTitle: "Asset Title", assetArtworkData: nil, options: options)

//在AppDelegate中设置会话委托 func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) { if identifier == "com.myapp.backgroundDownload" { assetDownloadSessionCompletionHandler = completionHandler } }

//在下载完成时调用completionHandler func urlSessionDidFinishEvents(forBackgroundURLSession session: URLSession) { if let completionHandler = assetDownloadSessionCompletionHandler { assetDownloadSessionCompletionHandler = nil completionHandler() } }

这样,在后台下载完成后,会话委托将自动调用,并调用应用程序委托中的相应方法。

相关内容

热门资讯

透视详细!wepoker有没有... 透视详细!wepoker有没有挂(透视)wpk有那种辅助吗,教程积累(有挂透明挂)-哔哩哔哩wpk有...
拱趴大菠萝开挂方法!竞技联盟透... 拱趴大菠萝开挂方法!竞技联盟透视(透视)插件-确实总结真的有挂暗藏猫腻,小编详细说明拱趴大菠萝开挂方...
透视开挂!hhpoker德州挂... 透视开挂!hhpoker德州挂真的有吗(透视)约局吧开挂神器是真的吗,教程模板(有挂工具)-哔哩哔哩...
epoker免费透视脚本!德州... epoker免费透视脚本!德州透视是真的假的(透视)app-都是揭露真的有挂1)德州透视是真的假的辅...
透视科普!fishpoker透... 透视科普!fishpoker透视底牌(透视)wepoker私人辅助器,教程指南书(证实有挂)-哔哩哔...
aapoker万能辅助器!wp... aapoker万能辅助器!wpk辅助哪里买(透视)技巧-本来揭露有挂该软件可以轻松地帮助玩家将aap...
透视了解!hhpoker辅助软... 透视了解!hhpoker辅助软件下载(透视)wepoker有插件吗,教程大纲(真是有挂)-哔哩哔哩1...
wejoker辅助器要钱玩吗!... wejoker辅助器要钱玩吗!线上德州的辅助器是什么(透视)软件-果然解迷有挂线上德州的辅助器是什么...
透视关于!wepoker透视有... 透视关于!wepoker透视有用吗(透视)wpk可以透视吗,教程窍门(有挂教学)-哔哩哔哩1、完成w...
aapoker真的假的!wep... aapoker真的假的!wepoker透视脚本下载(透视)挂-竟然详细存在有挂wepoker透视脚本...