0

画像をサーバーに送信できましたが、問題があります。次のような単純なブロックで失敗を確認できます。

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 には「failure:」がないことです ...

だから私の質問は...送信が失敗したかどうかを確認する方法はありますか??

ご協力いただきありがとうございます

4

2 に答える 2

1

これは正常に機能し、進行状況が示され、何か問題が発生した場合は失敗したブロックに移動します。

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-30T16:06:20.660 に答える