Il codice seguente consiste nell'invio di immagini tramite un'operazioneQueue. Le richieste vengono tutte attivate una alla volta correttamente, la risposta del server contiene il nome del file immagine di cui il client ha bisogno per accedere. Il problema è che non è previsto il reponseObject per il blocco di successo/fallimento JSON analizzato ma il tipo di NSInLineData mostrato nel debugger. Ora sospetto che il codice per costruire l'operazione da NSMutableURLRequest abbia causato il problema. Per favore aiuto.responseObject non è JSON ma NSInLineData per AFHTTPRequestOperationManager
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
NSMutableURLRequest *request = [manager.requestSerializer multipartFormRequestWithMethod:@"POST"
URLString:podURLString parameters:nil
constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
NSError *error;
BOOL success =[formData appendPartWithFileURL:imgURL name:@"images" fileName:img.path
mimeType:@"image/jpg" error:nil];
if (!success)
NSLog(@"appendPartWithFileURL error: %@", error);} error:nil];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Image Success: %@", [responseObject description]);
NSString *imagePath = [response objectForKey:@"imageFileName"];
[self.delegate networkManager:self didSubmitDeliveryImageForImageID:imagePath];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Image Error: %@", error);
NSLog(@"image error: %@", [operation.responseObject description]);
NSString *imageFilePath = [operation.responseObject objectForKey:@"imageFileName"];
[self.delegate networkManager:self didFailSubmitDeliveryImageForImageID:imageFilePath];
}];
[manager.operationQueue addOperation:operation];
rimozione di questa linea 'manager.responseSerializer = [AFJSONResponseSerializer serializzatore];' ha lavorato per me. – gabbler