我可以将图像发送到服务器,但我有一个问题。我可以像这样用简单的块检查故障:
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];但是我看不到这个块的发送进度。所以我找到了一个带有进度回调的特殊块,如下所示:
[operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
NSLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite);
}];
[httpClient enqueueHTTPRequestOperation:operation];问题是,在setUploadProgressBlock中没有“失败:”...
所以我的问题是。有一种方法可以检查发送是否失败??
谢谢你的帮忙
发布于 2013-05-31 00:06:21
这将工作得很好,它将给出进展,如果出现问题,还会转到失败的块:
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];发布于 2013-05-31 00:02:37
您可以设置这两个块,并实现您想要的。
https://stackoverflow.com/questions/16840841
复制相似问题