Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用AFNetworking 3.0和NSURLSessionDownloadTask Objective-C、OSX暂停/恢复下载_Objective C_Macos_Afnetworking - Fatal编程技术网

使用AFNetworking 3.0和NSURLSessionDownloadTask Objective-C、OSX暂停/恢复下载

使用AFNetworking 3.0和NSURLSessionDownloadTask Objective-C、OSX暂停/恢复下载,objective-c,macos,afnetworking,Objective C,Macos,Afnetworking,我在Objective-CosX应用程序中创建暂停/恢复下载方法时遇到问题,我尝试了这里找到的一些答案,但似乎没有任何效果 这是我的代码:`-(void)pauseDownload:(id)sender{ 如果(!downloadTask)返回 继续方法: -(void)continueDownload:(id)sender { if (!self.downloadResumeData) { return; } self.downloadTask = [manager.session d

我在Objective-CosX应用程序中创建暂停/恢复下载方法时遇到问题,我尝试了这里找到的一些答案,但似乎没有任何效果

这是我的代码:`-(void)pauseDownload:(id)sender{ 如果(!downloadTask)返回

继续方法:

-(void)continueDownload:(id)sender {
if (!self.downloadResumeData) {
    return;
}
self.downloadTask = [manager.session downloadTaskWithResumeData:self.downloadResumeData];
[self.downloadTask resume];
[self setDownloadResumeData:nil];}
和下载请求以及下载任务:

-(void)downloadRequest:(NSString *)url toDirectory:(NSString *)directoryName atIndex:(NSInteger) rowIndex {

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];

NSURL *URL = [NSURL URLWithString:url];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSString *downloadDirectoryPath = [[NSUserDefaults standardUserDefaults] objectForKey:@"downloadPath"];
NSURL *downloadURL;
if (directoryName != nil || ![directoryName isEqualToString:@""]) {
    downloadURL = [self createDownloadDirectoryIn:downloadDirectoryPath withName:directoryName];
} else {
    downloadURL = [NSURL URLWithString:[[NSUserDefaults standardUserDefaults] objectForKey:@"downloadFolderPath"]];
}
downloadTask = [manager downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull downloadProgress) {
    NSLog(@"%@", downloadProgress);

    //        [self downloadStartedWithDownloadId:downloadID andDeviceId:userDeviceID];

    isDownloading = YES;
    NSNumber *downloadPercentage = [NSNumber numberWithInteger:downloadProgress.fractionCompleted *100];
    progressArray[rowIndex] = downloadPercentage;
    [self updateProgressBars];

} destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
    return [downloadURL URLByAppendingPathComponent:[response suggestedFilename]];
} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {

    [[files objectAtIndex:self.tableOfContents.selectedRow] setIsFinishedDownloading:YES];
    //        [self downloadFinishedWithDownloadID:downloadID andDeviceID:userDeviceID];
    NSLog(@"File downloaded to: %@", filePath);
}] ;
[downloadTask resume];}
谢谢你的帮助

-(void)downloadRequest:(NSString *)url toDirectory:(NSString *)directoryName atIndex:(NSInteger) rowIndex {

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];

NSURL *URL = [NSURL URLWithString:url];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSString *downloadDirectoryPath = [[NSUserDefaults standardUserDefaults] objectForKey:@"downloadPath"];
NSURL *downloadURL;
if (directoryName != nil || ![directoryName isEqualToString:@""]) {
    downloadURL = [self createDownloadDirectoryIn:downloadDirectoryPath withName:directoryName];
} else {
    downloadURL = [NSURL URLWithString:[[NSUserDefaults standardUserDefaults] objectForKey:@"downloadFolderPath"]];
}
downloadTask = [manager downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull downloadProgress) {
    NSLog(@"%@", downloadProgress);

    //        [self downloadStartedWithDownloadId:downloadID andDeviceId:userDeviceID];

    isDownloading = YES;
    NSNumber *downloadPercentage = [NSNumber numberWithInteger:downloadProgress.fractionCompleted *100];
    progressArray[rowIndex] = downloadPercentage;
    [self updateProgressBars];

} destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
    return [downloadURL URLByAppendingPathComponent:[response suggestedFilename]];
} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {

    [[files objectAtIndex:self.tableOfContents.selectedRow] setIsFinishedDownloading:YES];
    //        [self downloadFinishedWithDownloadID:downloadID andDeviceID:userDeviceID];
    NSLog(@"File downloaded to: %@", filePath);
}] ;
[downloadTask resume];}