【问题标题】:ASINetworkQueue some image download failsASINetworkQueue 一些图片下载失败
【发布时间】:2011-10-30 18:36:35
【问题描述】:

我正在通过ASINetworkQueue 下载一堆图像。我在模拟器中没有问题,但在 iPad 上,一些图像(每次都不同)没有下载。我该如何解决这个问题?

代码如下:

队列创建:

if (addedPaintings > 0) {
            [currentPaintingsArray addObjectsFromArray:objectsToAdd];
            [unseenPaintings addObjectsFromArray:objectsToAdd];
            [self downloadImages];
        }
        // update plist file if data was altered.
        if (addedPaintings > 0 || removedPaintings > 0)
            [currentPaintingsArray writeToFile:dataFilePath atomically:YES];
        else
            [self completeSync:request.responseStatusCode];
}

图片下载方式:

- (void) downloadImages {
    [networkQueue reset];
    [networkQueue setDelegate:self];
    [networkQueue setShowAccurateProgress:YES];
    [networkQueue setDownloadProgressDelegate:self.progressView.customView];
    [networkQueue setQueueDidFinishSelector:@selector(imageQueueDownloadComplete:)];

    for (NSDictionary *dict in [Globals sharedGlobals].unseenPaintings) {       
        NSString *link = [dict objectForKey:@"link"];
        NSString *smallLink = [dict objectForKey:@"smallLink"];
        if ([link length] != 0) {
            NSURL *url = [NSURL URLWithString:[[URL stringByAppendingString:GALLERY] stringByAppendingString: link]];
            ASIHTTPRequest *downloadRequest = [[ASIHTTPRequest alloc] initWithURL:url];
            [downloadRequest setDownloadDestinationPath:[documentsDirectory stringByAppendingPathComponent:link]];
            [downloadRequest setDidFailSelector:@selector(imageDownloadFailed:)];
            [downloadRequest setDidFinishSelector:@selector(imageDownloadComplete:)];
            [downloadRequest setUserInfo:dict];
            [downloadRequest setDelegate:self];
            [networkQueue addOperation:downloadRequest];
            [downloadRequest release];

            NSURL *urlCarousel = [NSURL URLWithString:[[URL stringByAppendingString:WS_IMAGES] stringByAppendingString: smallLink]];
            downloadRequest = [[ASIHTTPRequest alloc] initWithURL:urlCarousel];
            [downloadRequest setDownloadDestinationPath:[documentsDirectory stringByAppendingPathComponent:smallLink]];
            [downloadRequest setDidFailSelector:@selector(imageDownloadFailed:)];
            [downloadRequest setUserInfo:dict];
            [downloadRequest setDelegate:self];
            [networkQueue addOperation:downloadRequest];
            [downloadRequest release];
        }
    }
    [networkQueue go];
}

【问题讨论】:

  • 你遇到了什么错误,你已经做了什么来调查这个,等等?
  • 我没有收到任何错误。我只是没有看到一些图像。我的猜测是,这个 ASINetworkQueue 有时会用另一个图像文件覆盖一个图像文件。
  • 我们只能猜测,因为您没有向我们展示代码。
  • 对不起,我现在发布代码。另外,如果我将下载方法从 networkQueue 更改为 [downloadRequest startAsynchronous],一切正常。

标签: ios asihttprequest


【解决方案1】:

根据您留给问题的 cmets(具体为:Also, if I change the download method from networkQueue to [downloadRequest startAsynchronous], everything works.),您的请求可能在同步运行时超时。

您应该知道的另一件事是不再维护“ASI 网络类”。开发者提供了多种选择in his blog post announcing the end-of-life of that software

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-28
    • 1970-01-01
    • 2020-07-25
    • 1970-01-01
    • 1970-01-01
    • 2016-01-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多