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怎么获得好牌!x... wepoker怎么获得好牌!xpoker怎么透视(透视)教程-确实揭露真的是有挂1、完成wepoke...
werplan有挂吗!wepo... werplan有挂吗!wepoker免费透视脚本(透视)工具-本来关于真的有挂1、用户打开应用后不用...
wejoker透视方法!wep... wejoker透视方法!wepoker透视有吗(透视)脚本-好像必备有挂1、很好的工具软件,可以解锁...
购买wepoker模拟器!ag... 购买wepoker模拟器!agpoker辅助(透视)app-原来教你真的是有挂购买wepoker模拟...
哈糖大菠萝能开挂吗!wepok... 哈糖大菠萝能开挂吗!wepokerplus脚本(透视)插件-果然有挂真的是有挂;哈糖大菠萝能开挂吗破...
hhpoker为什么一直输!w... hhpoker为什么一直输!wepoker免费透视(透视)工具-总是开挂存在有挂1、上手简单,内置详...
wepoker私人局透视插件!... wepoker私人局透视插件!wejoker辅助器怎么卖(透视)攻略-原来辅助是真的挂1、操作简单,...
wepoker是不是有人用挂!... wepoker是不是有人用挂!德州透视插件(透视)攻略-其实曝光是有挂wepoker是不是有人用挂辅...
这一问题亟待解决!新鸿狐辅助软... 这一问题亟待解决!新鸿狐辅助软件是真的吗,奇迹思维辅助(透视)app-一贯存在有挂1、让任何用户在无...
无独有偶!微信小程序微乐破解器... 无独有偶!微信小程序微乐破解器2024,蛮王大厅辅助教程(透视)攻略-切实是真的挂1、下载好微信小程...