Slide 21
Slide 21 text
࣮ͷ۩ମྫ
DelegateͰ݁ՌΛड͚औΔ
public final class BackgroundSessionTaskManager: NSObject {
public typealias CompletionHandler = (Result<(Data, HTTPURLResponse), Error>) -> Void
private var session: URLSession!
private var tasks: [Int: TaskWrapper] = [:]
public init(sessionIdentifier: String) {
super.init()
self.session = .init(
configuration: .background(withIdentifier: sessionIdentifier),
delegate: self,
delegateQueue: nil
)
}
func makeTask(with request: URLRequest, completionHandler: CompletionHandler?) -> URLSessionDownloadTask {
precondition(request.url?.scheme == "https")
let task = session.downloadTask(with: request)
tasks[task.taskIdentifier] = TaskWrapper(task: task, completionHandler: completionHandler)
return task
}
}