download continues while app is killed or sleeping • Callback closure is useless — if app is killed by system • Use delegate method to catch up what have been downloaded
= session.dataTask(with: url) { (data, response, error) in if let data = data { print(data as NSData) } } task.resume() task.taskIdentifier // task-id Integer • Needs keep this ID associate with article-id or other id • May be similar to use URL to identify the download owner • If you have other sessions, the ID may collide
• article-id?, path to save file?, managed object ID? • But this property is just a string let url = URL(string: "https://www.apple.com")! let task = session.dataTask(with: url) { (data, response, error) in if let data = data { print(data as NSData) } } task.taskDescription = "Some useful information" task.resume() String
• Schedule downloading • A ZDownloader for a session • delegate of URLSession • ask ZDownloaderDelegate to fetch / construct ZDownloadable • decode JSON and pass downloaded binary to ZDownloadable