Here is my case:
I have a Webview with text and some imgs,i used WebViewJavascriptBridge to get the img src(generally more than one pic) and downloaded in local use for-loop with SDWebImage succesfully.Like it:
for (NSUInteger i = 0; i < imageUrls.count; i++) {
NSString *_url = imageUrls[i];
[manager downloadImageWithURL:[NSURL URLWithString:_url] options:SDWebImageLowPriority progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
if (image) {
[_allImagesOfThisArticle replaceObjectAtIndex:i withObject:image];
NSString *key = [manager cacheKeyForURL:imageURL];
NSString *imageDiskPath = [manager.imageCache defaultCachePathForKey:key];
NSLog(@"图片在硬盘中的地址:%@",imageDiskPath);
[_bridge callHandler:@"imagesDownloadComplete" data:@[key,imageDiskPath]];
}
}];
}
When I call [_bridge callHandler:@"imagesDownloadComplete" data:@[key,imageDiskPath]]; , it invoked the function in JS named imagesDownloadComplete.Here is the JS code:
function imagesDownloadComplete(pOldUrl, pNewUrl) {
var allImage = document.querySelectorAll("img");
allImage = Array.prototype.slice.call(allImage, 0);
allImage.forEach(function(image) {
if (image.getAttribute("src") == pOldUrl || image.getAttribute("src") == decodeURIComponent(pOldUrl)) {
image.src = pNewUrl;
}
});
}
But the fact is,the webpage cannot load all images successfully,there always has some pics didn't load.Like this:

pls.
Here is my case:
I have a Webview with text and some imgs,i used WebViewJavascriptBridge to get the img src(generally more than one pic) and downloaded in local use for-loop with SDWebImage succesfully.Like it:
When I call
[_bridge callHandler:@"imagesDownloadComplete" data:@[key,imageDiskPath]];, it invoked the function in JS namedimagesDownloadComplete.Here is the JS code:But the fact is,the webpage cannot load all images successfully,there always has some pics didn't load.Like this:
pls.