Skip to content

[Bug] _dispatchMessage has a multiple queue issue #137

@KittenYang

Description

@KittenYang

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:

img_4775

pls.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions