Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.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
Ios AF3.0预期写入返回的总字节数-1_Ios_Objective C_Afnetworking 3 - Fatal编程技术网

Ios AF3.0预期写入返回的总字节数-1

Ios AF3.0预期写入返回的总字节数-1,ios,objective-c,afnetworking-3,Ios,Objective C,Afnetworking 3,我想配置进度条,但我的url无法提供图像的总大小。我遵循这个教程 如果totalBytesExpectedToWrite为-1,则服务器配置存在一些问题,因为它没有响应映像的总大小 如果没有总大小,就不可能创建正确的进度条,您只能显示一些活动指示器(仅指示正在发生的事情,但不会在完成时给出反馈) 我建议查看您的服务器设置(尤其是设置正确的内容长度标题)。如果totalBytesExpectedToWrite为-1,则您的服务器配置有一些问题,因为它没有响应图像的总大小 如果没有总大小,就不可能创

我想配置进度条,但我的url无法提供图像的总大小。我遵循这个教程


如果
totalBytesExpectedToWrite
为-1,则服务器配置存在一些问题,因为它没有响应映像的总大小

如果没有总大小,就不可能创建正确的进度条,您只能显示一些活动指示器(仅指示正在发生的事情,但不会在完成时给出反馈)


我建议查看您的服务器设置(尤其是设置正确的
内容长度
标题)。

如果
totalBytesExpectedToWrite
为-1,则您的服务器配置有一些问题,因为它没有响应图像的总大小

如果没有总大小,就不可能创建正确的进度条,您只能显示一些活动指示器(仅指示正在发生的事情,但不会在完成时给出反馈)

我建议查看您的服务器设置(尤其是设置正确的
内容长度
标题)。

尝试以下方法:

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

NSURL * URL = [NSURL URLWithString:@"http://static1.visitfinland.com/wp-content/uploads/Header_Linnunlaulu_ruska_autumn.jpg"];
NSURLRequest * request = [NSURLRequest requestWithURL:URL];

NSURLSessionDownloadTask * downloadTask = [manager downloadTaskWithRequest:request
                                                                  progress:^(NSProgress * _Nonnull downloadProgress) {
    dispatch_async(dispatch_get_main_queue(), ^{
        // here you will be able to set progress to your progress view
        [yourProgressView setProgress:downloadProgress.fractionCompleted];
    });
} destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
    NSURL * documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory
                                                                           inDomain:NSUserDomainMask
                                                                  appropriateForURL:nil
                                                                             create:NO
                                                                              error:nil];

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

}];

[downloadTask resume];
试试这个:

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

NSURL * URL = [NSURL URLWithString:@"http://static1.visitfinland.com/wp-content/uploads/Header_Linnunlaulu_ruska_autumn.jpg"];
NSURLRequest * request = [NSURLRequest requestWithURL:URL];

NSURLSessionDownloadTask * downloadTask = [manager downloadTaskWithRequest:request
                                                                  progress:^(NSProgress * _Nonnull downloadProgress) {
    dispatch_async(dispatch_get_main_queue(), ^{
        // here you will be able to set progress to your progress view
        [yourProgressView setProgress:downloadProgress.fractionCompleted];
    });
} destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
    NSURL * documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory
                                                                           inDomain:NSUserDomainMask
                                                                  appropriateForURL:nil
                                                                             create:NO
                                                                              error:nil];

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

}];

[downloadTask resume];

如果您正在尝试执行进度条,请尝试:
[operation setUploadProgressBlock:…
这是到block code的链接,我在这篇文章中看不到任何问题。你想实现什么,需要什么帮助?请编辑原始文章!@Nazir我想从服务器下载而不是上传。当我们下载时,我们不知道有多少下载内容。因此,你能在这方面帮助我吗?如果你愿意的话正在尝试执行进度条尝试:
[operation setUploadProgressBlock:…
这是到block code的链接,我在这篇文章中看不到任何问题。你想实现什么,需要什么帮助?请编辑原始文章!@Nazir我想从服务器下载而不是上传。当我们下载时,我们不知道有多少下载内容。所以你能帮我一下吗?我知道如果没有总尺寸,我不能做流程栏。服务器问题是什么?你能描述一下吗?那么你的问题是什么?你能帮助我详细了解服务器配置吗?我使用cpanel,所以请给我详细步骤我知道没有总尺寸,我不能做流程栏。服务器问题是什么?你能描述一下吗?那么你的问题是什么gh?你能详细地帮助我配置服务器吗?我使用cpanel,所以请给我详细的步骤。这个解决方案很好。但在我的项目中必须使用AFNetworking 3.0。是的,但如果你看到AFNetworking 3.0与
AFURLSessionManager
一起使用,这里还有一个示例:。这个解决方案很好。但必须使用AFNe在我的项目中使用tworking 3.0。是的,但如果您看到有人将AFNetworking 3.0与
AFURLSessionManager
一起使用,这里还有一个示例:。