ios-sdk icon indicating copy to clipboard operation
ios-sdk copied to clipboard

How to invalidate the cached image of a generated Scannable's skin's imageURI?

Open laus102 opened this issue 7 years ago • 1 comments

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?

laus102 avatar May 18 '18 16:05 laus102

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()
}

janekp avatar May 20 '18 17:05 janekp