I needed to load images from the iCloud Document Storage in my WebView I have solved this problem with my own implementation of the NSURLProtocol. My problem is, that the download is very slow and the User doesn't see any Indicator in the web page that an image is getting downloaded.
I want to show a placeholder image until the download of the real image is accomplished:
public class EDAMResourceURLProtocol : NSURLProtocol
{
public override func startLoading() {
let url = self.request.URL!
let hash = url.host!
// I want to show this image before the real content gets downloaded
let image = UIImage(named: "DownloadPlaceholder")
// this function is very slow ....
historyStorage.fetchResourceWithBody(hash, success: {
edamResource in
let response = NSURLResponse(URL: self.request.URL!, MIMEType: edamResource!.mime, expectedContentLength: edamResource!.data!.body!.length, textEncodingName: nil)
self.client!.URLProtocol(self, didReceiveResponse: response, cacheStoragePolicy: NSURLCacheStoragePolicy.NotAllowed)
self.client!.URLProtocol(self, didLoadData: edamResource!.data!.body)
self.client!.URLProtocolDidFinishLoading(self)
}
Do you have any ideas how I can show a placeholder until the real content is available?