1

我想从 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];

怎么了?

4

0 回答 0