使用AFNetworking下载时获取TimeOut异常

时间:2013-04-30 13:10:04

标签: afnetworking

我想从Amazon S3服务器下载超过5个视频文件到iPad。

直到5个文件,它运作良好。但如果我要下载7个文件,则最后2个文件会给出"请求超时。"

这是我的代码:

    NSMutableURLRequest* rq = [[APIClient sharedClient] requestWithMethod:@"GET" path:[[self item] downloadUrl] parameters:nil];
downloadOperation = [[AFHTTPRequestOperation alloc] initWithRequest:rq] ;
downloadOperation.outputStream = [NSOutputStream outputStreamToFileAtPath:[[self item] localUrl] append:NO];
[downloadOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"Successfully downloaded file to %@", [[self item] localUrl]);
    isDownloading = NO;
    [self.downloadProgressView setHidden:YES];
    [self setUserInteractionEnabled:YES];
    [self.downloadIndicatorView stopAnimating];

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
    [self.downloadProgressView setHidden:YES];
    [self setUserInteractionEnabled:YES];
    [self.downloadIndicatorView stopAnimating];

    isDownloading = NO;

    [[[UIAlertView alloc] initWithTitle:@"Hata"
                                message:@"Bir hata oluştu. Lütfen tekrar deneyiniz."
                               delegate:self
                      cancelButtonTitle:@"Tamam"
                      otherButtonTitles:nil] show];
}];
[downloadOperation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
    float progress = totalBytesRead / (float)totalBytesExpectedToRead;
    //NSLog(@"Download Percentage: %f %%", progress*100);
    [self.downloadProgressView setProgress:progress animated:YES];
}];
[downloadOperation setShouldExecuteAsBackgroundTaskWithExpirationHandler:^{

}];

[SharedAppDelegate.httpClient enqueueHTTPRequestOperation:downloadOperation];
[downloadOperation start];
isDownloading = YES;
[self.downloadProgressView setHidden:NO];
[self.downloadIndicatorView startAnimating];

有什么问题?

0 个答案:

没有答案
相关问题