Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func start() {
- if let t = task {
- if t.state == .suspended {
- t.resume()
- }
- }
- else {
- if self.photo.servingUrlImage == nil {
- PhotoUtil.util.arrPhotosBeingDownloaded.removeDownload(self)
- PhotoUtil.util.continueDownloading(self.photo)
- }
- if let url = URL(string: self.photo.servingUrlImage) {
- let session = URLSession(configuration: URLSessionConfiguration.default)
- let request = Foundation.URLRequest(url: url)
- task = session.dataTask(with: request, completionHandler: { data, response, error in
- do {
- if error == nil {
- if let image = UIImage(data: data!) {
- self.callback?(image)
- serialQueue.sync {
- PhotoUtil.util.arrPhotosBeingDownloaded.removeDownload(self)
- PhotoUtil.util.continueDownloading(self.photo)
- }
- PhotosUtil.savePic(self.photo.id, image: image)
- self.photo.downloadedStatus = .downloaded
- DispatchQueue.main.asyncAfter(deadline: .now() + 1.0, execute: {
- session.finishTasksAndInvalidate()
- })
- } else {
- print("error getting image")
- }
- } else {
- print(error?.localizedDescription)
- }
- }
- })
- task?.resume()
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement