AFDownloadRequestOperation和ASIHTTPRequest不恢复下载

时间:2014-02-14 07:05:43

标签: ios networking dropbox afnetworking-2

我陷入了恢复下载的困境。我正在使用AFDownloadRequestOperationDropbox公共链接下载文件。一切(下载和恢复)都很顺利。但突然间我不知道发生了什么事情,下载工作正常,但在应用程序重启恢复工作不起作用,每次都给"Request Timeout"。虽然链接其他,然后Dropbox(公共链接)下载和恢复都工作正常。我也尝试过与ASIHTTPRequest相同并且表现相同。那么Dropbox公共链接有什么问题呢?或者对这些库有任何限制吗?

请帮助我非常担心我的项目的进展。由于此问题,项目进度停止。

这是我的代码

 __weak typeof(self) weakSelf = self;
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:url.absoluteString.lastPathComponent];

operation = [[AFDownloadRequestOperation alloc] initWithRequest:request targetPath:path shouldResume:YES];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
    AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    [appDelegate.downloadQueue removeObject:url.absoluteString];
    [weakSelf checkDownloadQueueForMoreDownload];
    NSLog(@"Successfully downloaded file to %@", path);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];
[operation setProgressiveDownloadProgressBlock:^(AFDownloadRequestOperation *operation, NSInteger bytesRead, long long totalBytesRead, long long totalBytesExpected, long long totalBytesReadForFile, long long totalBytesExpectedToReadForFile) {

    if (totalBytesExpected != totalBytesExpectedToReadForFile &&( weakSelf.isDefaultProgressSet == NO)) {
        long long bytesHasWritten = totalBytesExpectedToReadForFile-totalBytesExpected;
        [weakSelf.delegate downloadedNumberOfBytes:((float)bytesHasWritten/
                                                    (float)totalBytesExpectedToReadForFile)
                                                    forAnnotaionView:annotView];
        weakSelf.isDefaultProgressSet = YES;
    }
    NSLog(@"Operation%i: bytesRead: %d", 1, bytesRead);
    NSLog(@"Operation%i: totalBytesRead: %lld", 1, totalBytesRead);
    NSLog(@"Operation%i: totalBytesExpected: %lld", 1, totalBytesExpected);
    NSLog(@"Operation%i: totalBytesReadForFile: %lld", 1, totalBytesReadForFile);
    NSLog(@"Operation%i: totalBytesExpectedToReadForFile: %lld", 1, totalBytesExpectedToReadForFile);
    float progress = ((float)totalBytesReadForFile/(float)totalBytesExpectedToReadForFile);
    [weakSelf.delegate downloadedNumberOfBytes:progress forAnnotaionView:annotView];
}];
[operation start];

继续恢复总是进入失败阻止。

0 个答案:

没有答案