ios-sdk
ios-sdk copied to clipboard
How to invalidate the cached image of a generated Scannable's skin's imageURI?
If we want to change the image associated with a scannable, how do we refresh the image?
I noticed that you can set skin.imageURI to either a local or remote URI, and setting it to a local one then calling reload() works well, but when we change the image at a certain remote URI, it seems that the Scannable skin is caching the image value for that URI.
If this is correct, how do we clear the cache for a remote image URI?
Caching is done by iOS / NSURLSession API. The easiest workaround is to add a timestamp to every URL (myURL?_t=current_time)
Another possible solution is to clear cache manually (untested)
if #available(iOS 9.0, *) {
let cacheTypes = NSSet(array: [WKWebsiteDataTypeDiskCache, WKWebsiteDataTypeMemoryCache])
WKWebsiteDataStore.default().removeData(ofTypes: cacheTypes as! Set<String>, modifiedSince: Date(timeIntervalSince1970: 0), completionHandler: { })
} else {
URLCache.shared.removeAllCachedResponses()
}