首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AFNetworking - AFHTTPRequestOperation - setUploadProgressBlock检查失败?

AFNetworking - AFHTTPRequestOperation - setUploadProgressBlock检查失败?
EN

Stack Overflow用户
提问于 2013-05-31 00:01:33
回答 2查看 1.2K关注 0票数 0

我可以将图像发送到服务器,但我有一个问题。我可以像这样用简单的块检查故障:

代码语言:javascript
复制
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"success: %@", operation.responseString);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"error: %@",  operation.responseString);
    }
 ];
[operation start];

但是我看不到这个块的发送进度。所以我找到了一个带有进度回调的特殊块,如下所示:

代码语言:javascript
复制
[operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
    NSLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite);
}];
[httpClient enqueueHTTPRequestOperation:operation];

问题是,在setUploadProgressBlock中没有“失败:”...

所以我的问题是。有一种方法可以检查发送是否失败??

谢谢你的帮忙

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-05-31 00:06:21

这将工作得很好,它将给出进展,如果出现问题,还会转到失败的块:

代码语言:javascript
复制
NSURLRequest *request = [[NSURLRequest alloc] init];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
 NSLog(@"success: %@", operation.responseString);
 }
 failure:^(AFHTTPRequestOperation *operation, NSError *error) {
 // If access token is null , we ask to the user if he wants to sign in or sign up ????
 NSLog(@"error: %@",  operation.responseString);
 }
 ];
 [operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
 NSLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite);
 }];
[operation start];
票数 1
EN

Stack Overflow用户

发布于 2013-05-31 00:02:37

您可以设置这两个块,并实现您想要的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16840841

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档