12

Is there any way to access the response data in the success block for a request using the object manager?

[objectManager postObject:[User class] path:@"/users" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
  NSLog(@"success");
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
  NSLog(@"failure");
}];

It seems like there should be some way to use the mapping or operation to get this information as maybe NSData or something.

fzf
  • 931
  • 1
  • 9
  • 19

2 Answers2

32

You can get this info from the RKObjectRequestOperation *operation

operation.HTTPRequestOperation.response
operation.HTTPRequestOperation.responseData
operation.HTTPRequestOperation.responseString
fzf
  • 931
  • 1
  • 9
  • 19
6

try this

[objectRequestOperation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {

// parse the response---       
 NSDictionary *myDic = [NSJSONSerialization JSONObjectWithData:operation.HTTPRequestOperation.responseData options:NSJSONReadingMutableLeaves error:nil];
  NSLog(@"=======:%@",myDic);
   NSLog(@"MY email============ %@ ",[myDic objectForKey:@"Email"]);      
    } failure:^(RKObjectRequestOperation *operation, NSError *error) {
        RKLogError(@"Operation failed with error: %@", error);
    }];
Deepak Sasindran
  • 494
  • 1
  • 6
  • 13