Posts

Post marked as solved
8 Replies
hello, i have a question about this.i use alamofire to download a file, and i cancel the task when the app terminate like this:public func applicationWillTerminate(_ application: UIApplication) { let sem = DispatchSemaphore(value: 0) Account.current?.downloadManager?.clean(completionHandler: { sem.signal() }) sem.wait() }i want to get the resumeData and save it to local when the completionHandler of the request called.below is the 'clean' method and the completionHandler:public func clean(completionHandler: (() -> Void)? = nil) { self.completionHandler = completionHandler request?.cancel() }let queue = DispatchQueue.init(label: "test") request?.response(queue: queue, completionHandler: { (resp) in if self.state != .initial { // all tasks had been cleared queue.async { Account.current?.userDefaults.set(resp.resumeData, forKey: self.resumeDataKey) Account.current?.userDefaults.synchronize() self.completionHandler?() } } }this method works fine if user kill the app and relaunch it. but when the app enter background and be killed by the system a few minutes later, it doesn't work.thank you for your time, i would be very appreciate if you can help me!