Reputation: 2691
I could send an image to a server, but I have a problem. I can check failure with simple block like this :
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];
But I can't see the progress of the sending with this block. So I found a special block with progress call back like this :
[operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
NSLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite);
}];
[httpClient enqueueHTTPRequestOperation:operation];
The problem is that with setUploadProgressBlock there is not "failure: " ...
So my question is... There is a way to check if sending failed or no??
Thanks for your help
Upvotes: 0
Views: 1162
Reputation: 4140
This will be working fine, it will give progress and also go to failed block if something gone wrong:
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];
Upvotes: 1