ios - Issue migrating from AFNetworking 1.3 to AFNetworking 2.0 -


i'm trying migrate project afnetworking 1.3 afnetworking 2.0.

in afnetworking 1.3 project have code:

- (void) downloadjson:(id)sender {      nsurlrequest *request = [nsurlrequest requestwithurl:[nsurl urlwithstring:@"http://myserver/api/call?param1=string1&param2=string2"]];      afjsonrequestoperation *operation = [afjsonrequestoperation jsonrequestoperationwithrequest:request success:^(nsurlrequest *request, nshttpurlresponse *response, id json) {          // handle success      } failure:^(nsurlrequest *request, nshttpurlresponse *response, nserror *error, id json) {         nslog(@"%ld", (long)[response statuscode]);          nsdictionary *data = json;         nsstring *errormsg = [data objectforkey:@"descriptiveerrormessage"];         // handle failure      }];      [operation start];  } 

when client sends url not formatted or bad parameters server sends 400 error , includes json “descriptiveerrormessage” read in failure block. use “descriptiveerrormessage” determine wrong url , message user if appropriate.

the code afnetworking 2.0 project looks this:

- (void)downloadjson:(id)sender {  nsurlrequest *request = [nsurlrequest requestwithurl:[nsurl urlwithstring:@"http://myserver/api/call?param1=string1&param2=string2"]];      afhttprequestoperation *operation = [[afhttprequestoperation alloc] initwithrequest:request];      operation.responseserializer = [afjsonresponseserializer serializer];      [operation setcompletionblockwithsuccess:^(afhttprequestoperation *operation, id responseobject) {          // handle success      } failure:^(afhttprequestoperation *operation, nserror *error) {          // way json on 400 error?      }];      [operation start]; } 

in afnetworking 2.0 project don't see way json read “descriptiveerrormessage” sent server. can response headers nshttpurlresponse in operation thats far can get, maybe i'm missing something.

is there way json in failure block? if not can suggest better way of doing this?

thanks in advance problem.

i think try , access responsedata property of passed operation parameter failure block.

not sure contain json data server sends back, information should there.

hope helps.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -