Comments (4)
Hi, for me worked following:
`class ImageDownloader {
private var imageDataTask: URLSessionDataTask?
private let cache = ImageCache.cache
private(set) var isCancelled = false
func downloadPhoto(with url: URL, completion: @escaping ((UIImage?, Bool) -> Void)) {
guard imageDataTask == nil else { return }
isCancelled = false
if let cachedResponse = cache.cachedResponse(for: URLRequest(url: url)),
let image = UIImage(data: cachedResponse.data) {
completion(image, true)
return
}
let config = URLSessionConfiguration.default
config.urlCache = cache
let session = URLSession(configuration: config)
imageDataTask = session.dataTask(with: url) { [weak self] (data, response, error) in
guard let strongSelf = self else { return }
strongSelf.imageDataTask = nil
guard let data = data, let response = response, let image = UIImage(data: data), error == nil else { return }
let cachedResponse = CachedURLResponse(response: response, data: data)
strongSelf.cache.storeCachedResponse(cachedResponse, for: URLRequest(url: url))
DispatchQueue.main.async {
completion(image, false)
}
}
imageDataTask?.resume()
}
func cancel() {
isCancelled = true
imageDataTask?.cancel()
}
}
`
this bit is important:
`let config = URLSessionConfiguration.default
config.urlCache = cache
let session = URLSession(configuration: config)
imageDataTask = session.dataTask(with: url) { [weak self]...`
the cache has to be asigned to the session.
hope it helps
from unsplash-photopicker-ios.
There is an open pull request #34 related to this issue. @ocollet, what needs to be done to fix the caching issue?
from unsplash-photopicker-ios.
... let config = URLSessionConfiguration.default config.urlCache = cache let session = URLSession(configuration: config) imageDataTask = session.dataTask(with: url) { [weak self] (data, response, error) in ...
This didn't work for me
from unsplash-photopicker-ios.
Fixed with pull-request #34
from unsplash-photopicker-ios.
Related Issues (20)
- Problem with build on Mac Catalyst HOT 1
- Question about using this framework HOT 1
- Serialization Issues in UnsplashPhoto and UnsplashUser HOT 1
- images do not load
- Description
- SPM Support HOT 4
- API misuse HOT 2
- Hi
- Could not load NIB with name 'PhotoView' HOT 1
- Code
- Invalid exclude '.../UnsplashPhotoPicker.h': File not found.
- Server Error HOT 1
- many warning: **'unregisterForPreviewing(withContext:)' was deprecated in iOS 13.0
- Is this repo maintained? HOT 3
- Photo Picker Configuration on Obj-C HOT 1
- add a showSearchBar parameter to UnsplashPhotoPickerConfiguration
- author clickable link HOT 2
- change background color of the picker
- SERVER ERROR DUE TO SCHEMA CHANGE HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unsplash-photopicker-ios.