ios - Update UI on main thread from AFHTTPRequestOperation -


i've built rails backend ios app lets users access restful api after having authorized device. authorization managed retrieving token.

when user submits username , password, webservice gets called afhttprequestoperation (see code below). display user hud (mbprogresshud) track progress of request. i've set callbacks success , failure , want update hud , let stick onscreen updated message couple of seconds before dismissing it.

//set hud mbprogresshud *hud = [mbprogresshud showhudaddedto:self.view animated:yes]; hud.mode = mbprogresshudmodeindeterminate; hud.labeltext = @"authenticating";  //set http client , request nsurl *url = [nsurl urlwithstring:@"http://localhost:3000"]; afhttpclient *httpclient = [[afhttpclient alloc] initwithbaseurl:url]; [httpclient setparameterencoding:afformurlparameterencoding]; //setting x-www-form-urlencoded nsmutableurlrequest *request = [httpclient requestwithmethod:@"post" path:@"/api/v1/tokens.json" parameters:@{@"password":_passwordfield.text, @"email":_emailfield.text}];  //set operation afhttprequestoperation *operation = [[afhttprequestoperation alloc] initwithrequest:request];  //success , failure blocks [operation setcompletionblockwithsuccess:^(afhttprequestoperation *operation, id responseobject){     nserror *error;     nsdictionary* jsonfromdata = (nsdictionary*)[nsjsonserialization jsonobjectwithdata:responseobject options:nsjsonreadingmutablecontainers error:&error];     nslog(@"%@", jsonfromdata);     _statuslabel.text = @"device authenticated!";     hud.customview = [[uiimageview alloc] initwithimage:[uiimage imagenamed:@"37x-checkmark.png"]];     hud.mode = mbprogresshudmodecustomview;     hud.labeltext = @"authenticated!";     sleep(2);     [mbprogresshud hideallhudsforview:self.view animated:yes]; } failure:^(afhttprequestoperation *operation, nserror *error){     nslog(@"error");     sleep(2);     _statuslabel.text = @"wrong username or password!";     [mbprogresshud hideallhudsforview:self.view animated:yes]; }]; 

when success / failure operation callbacks called:

  • i try update hud mode , text;
  • i wait sleep() couple of seconds;
  • i dismiss hud [mbprogresshud hideallhudsforview:self.view animated:yes];;

i've tried using dispatch_queue_t dispatch_get_main_queue(void); , run hud update on main thread no avail.

any ideas on getting wrong?


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -