diff --git a/GiGLibrary.xcodeproj/project.pbxproj b/GiGLibrary.xcodeproj/project.pbxproj index 5bd7367..d60938d 100644 --- a/GiGLibrary.xcodeproj/project.pbxproj +++ b/GiGLibrary.xcodeproj/project.pbxproj @@ -2698,7 +2698,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 3.4; + MARKETING_VERSION = 3.4.1; ONLY_ACTIVE_ARCH = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.gigigo.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -2727,7 +2727,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 3.4; + MARKETING_VERSION = 3.4.1; PRODUCT_BUNDLE_IDENTIFIER = "com.gigigo.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; diff --git a/README.md b/README.md index 4cd6821..3497429 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![Build Status](https://travis-ci.org/gigigoapps/gigigo-ios-lib.svg?branch=master)](https://travis-ci.org/gigigoapps/gigigo-ios-lib) ![Language](https://img.shields.io/badge/Language-Objective--C-orange.svg) ![Language](https://img.shields.io/badge/Language-Swift-orange.svg) -![Version](https://img.shields.io/badge/version-3.3.1-blue.svg) +![Version](https://img.shields.io/badge/version-3.4.1-blue.svg) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) diff --git a/Source/GIGUtils/Image/ImageDownloader.swift b/Source/GIGUtils/Image/ImageDownloader.swift index e6e9efa..569c020 100644 --- a/Source/GIGUtils/Image/ImageDownloader.swift +++ b/Source/GIGUtils/Image/ImageDownloader.swift @@ -51,7 +51,7 @@ struct ImageDownloader { ImageDownloader.queue[view] = request ImageDownloader.stack.append(view) - if ImageDownloader.queue.count <= 3 { + if ImageDownloader.stack.count <= 3 { self.downloadNext() } } @@ -59,7 +59,6 @@ struct ImageDownloader { private func downloadNext() { guard let view = ImageDownloader.stack.popLast() else { return } guard let request = ImageDownloader.queue[view] else { - self.downloadNext() return } @@ -67,41 +66,44 @@ struct ImageDownloader { switch response.status { case .success: - DispatchQueue.global().async { - if let image = try? response.image() { - DispatchQueue.main.async { - let width = view.width() * UIScreen.main.scale - let height = view.height() * UIScreen.main.scale - let resized = image.imageProportionally(with: CGSize(width: width, height: height)) - ImageDownloader.images[request.baseURL] = resized + if let image = try? response.image() { + DispatchQueue(label: "com.gigigo.imagedownloader", qos: .background).async { + var finalImage = image + let width = view.width() * UIScreen.main.scale + let height = view.height() * UIScreen.main.scale + if let resized = image.imageProportionally(with: CGSize(width: width, height: height)) { + finalImage = resized + } + ImageDownloader.images.updateValue(finalImage, forKey: request.baseURL) - if let currentRequest = ImageDownloader.queue[view], request.baseURL == currentRequest.baseURL { - self.setAnimated(image: resized, in: view) - } - - if let index = ImageDownloader.queue.index(forKey: view) { - ImageDownloader.queue.remove(at: index) - } - self.downloadNext() - } - } else if let imageGif = try? response.gif() { + DispatchQueue.main.async { - ImageDownloader.images[request.baseURL] = imageGif - if let currentRequest = ImageDownloader.queue[view], request.baseURL == currentRequest.baseURL { - self.setAnimated(image: imageGif, in: view) - } - + self.setAnimated(image: finalImage, in: view) + } if let index = ImageDownloader.queue.index(forKey: view) { ImageDownloader.queue.remove(at: index) } self.downloadNext() } - } else { - LogWarn("Al descargar la imagen,o se ha recibido un body vacio o no se se ha reconocido el tipo de imagen que es.") - self.downloadNext() - } - } + } + } else if let imageGif = try? response.gif() { + DispatchQueue.main.async { + ImageDownloader.images.updateValue(imageGif, forKey: request.baseURL) + + if let currentRequest = ImageDownloader.queue[view], request.baseURL == currentRequest.baseURL { + self.setAnimated(image: imageGif, in: view) + } + + if let index = ImageDownloader.queue.index(forKey: view) { + ImageDownloader.queue.remove(at: index) + } + self.downloadNext() + } + } else { + LogWarn("Al descargar la imagen,o se ha recibido un body vacio o no se se ha reconocido el tipo de imagen que es.") + self.downloadNext() + } default: LogError(response.error)