遇到一个崩溃,Task created in a session that has been invalidated
gaoruiqing187 opened this issue · 1 comments
gaoruiqing187 commented
bugly上显示一个崩溃,次数很多,我不知道哪里写错了 ,求指教 Task created in a session that has been invalidated
var sessionManager: SessionManager?
func createDownloadSession(identifier: String) {
var config = SessionConfiguration.init()
if #available(iOS 13, *) {
config.allowsExpensiveNetworkAccess = true
config.allowsConstrainedNetworkAccess = true
config.allowsCellularAccess = false
}
self.sessionManager = SessionManager(identifier, configuration: config)
}
func createDownloadTask(urlStr: String) -> DownloadTask? {
guard let url = URL(string: urlStr) else { return nil }
if (self.sessionManager == nil) {return nil}
let task = self.sessionManager?.download(url)
return task
}
Danie1s commented
sessionManager 生命周期问题,最好别销毁,具体的看一下文档