ios - How to timeout or detect slow response in AFHTTPSessionManager in AFNetworking? -
ios - How to timeout or detect slow response in AFHTTPSessionManager in AFNetworking? -
with code below, failure block fires if there no net connection - , good. if there connection, no internet?
i've read question: how set timeout afnetworking suggests utilize reachabilitymanager , illustration in reply shows utilize - afnetworking 2.0 queue request when device offline setreachabilitystatuschangeblock nothing.
but, if simulator or phone connected wifi network not have net access (dns, dhcp, or modem issues), code @ nowadays continues seek reach api long time. i'm not downloading , know script , server should respond in seconds know after 5 seconds of inactivity, wrong.
so can safely timeout, or can utilize reachabilitymanager in current script observe if script (not internet) not reachable , if so, how?
- (void)apicall:(nsmutabledictionary*)params { nsurl *baseurl = [nsurl urlwithstring:baseurlstring]; nsdictionary *parametersgetauthcode = @{@"req": @"getauth"}; afhttpsessionmanager *manager = [[afhttpsessionmanager alloc] initwithbaseurl:baseurl]; manager.responseserializer = [afjsonresponseserializer serializer]; [manager post:apiscript parameters:parametersgetauthcode success:^(nsurlsessiondatatask *task, id responseobject) { if ([task.response iskindofclass:[nshttpurlresponse class]]) { nshttpurlresponse *r = (nshttpurlresponse *)task.response; if ([r statuscode] == 200) { //do success stuff } } } failure:^(nsurlsessiondatatask *task, nserror *error) { uialertview *alertview = [[uialertview alloc] initwithtitle:@"error" message:[error localizeddescription] delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil]; [alertview show]; //do failure stuff }]; }
just figure out reasonable timeout interval app , set on afhttpsessionmanager request serializer.
[manager.requestserializer settimeoutinterval:20.0];
add ui, uiactivityindicatorview or "downloading..." message user knows happening.
ios objective-c afnetworking
Comments
Post a Comment