2

AFNetworkingがファイルのアップロードを終了したかどうかを確認するにはどうすればよいですか?そして、どうすれば問題があったかどうかを確認できますか?

これは私のコードです:

AFHTTPClient *client= [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"http://server"]];
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
[parameters setObject:[fieldName text] forKey:@"name"];
[parameters setObject:[fieldSurname text] forKey:@"surname"];

NSMutableURLRequest *myRequest = [client multipartFormRequestWithMethod:@"POST" path:@"/upload.php" parameters:parameters constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
    [formData appendPartWithFileData:[[AttachedFile sharedAttachedFile]dataToSend] mimeType:@"image/jpeg" name:@"attach"];
}];

AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] initWithRequest:myRequest] autorelease]; 
[operation setUploadProgressBlock:^(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) {
    NSLog(@"Sent %d of %d bytes", totalBytesWritten, totalBytesExpectedToWrite);
}];

queue = [[[NSOperationQueue alloc] init] autorelease];
[queue addOperation:operation];

どのメソッド(およびデリゲート)を実装する必要がありますか?

ありがとう!

4

2 に答える 2

3

使用する

[AFHTTPRequestOperation HTTPRequestOperationWithRequest:myRequest
                                                success:(void (^)(id object))success 
                                                failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure];

それ以外の

AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] initWithRequest:myRequest] autorelease]; 

ファイルが完全にアップロードされると、成功ブロックが呼び出されます。問題がある場合は、障害ブロックが呼び出されます。

于 2011-11-07T15:59:48.033 に答える
0

HTTPRequestOperationWithRequestは非推奨です。AFHTTPRequestOperationインスタンスでsetCompletionBlockWithSuccess:failureを使用することをお勧めします。

AFNetworkingでmatttの回答を確認してくださいファイルのアップロード

于 2012-08-15T21:50:49.343 に答える