I'm loading a local html with a < img> tag e.g. :
< img class="icon" src="data:image/png;base64,/9j/4AAQSkZJRgABAQEAlgCWAAD/7gAOQWRvYmUAZAAAAAAA/...
However, how can I detect if the image is fully loaded? I'm using this to detect. However, it doesn't seem to work. Sometimes the image is loaded, sometimes it's not.
-(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
if (webView.isLoading) return;
..
//proceed to load the second html
}
Update:
I've added a delay in the didFinishNavigation delegate and the image is loaded perfectly:
-(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
if (webView.isLoading) return;
double delayInSeconds = 3.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
NSLog(@"Do some work");
});
}
However, this is an interim solution. Is there a better solution?