objective c - Network connection lost while switching from wifi to 3g -
i have run strange problem, both, reachability , nsurlconnection showing error (no internet connection/network connection lost) after switching wifi 3g. although apps running fine after switching 3g. double check if mobile data on app , device well. reinstalling apps works fine, please help. here reachability code:
-(bool)tochecknetworkstatus { internetreachable = [reachability reachabilityforinternetconnection]; [internetreachable startnotifier]; networkstatus internetstatus = [internetreachable currentreachabilitystatus]; if(internetstatus == notreachable ){ [self displaytoastwithmessage:@"connection lost!" andsubtitle:@"please check network connection." delay:3.2]; return no; } else{ return yes; } }
code fo nsurlconnection:
nserror *error; nsdata *postdata = [nsjsonserialization datawithjsonobject:dictionary options:0 error:&error]; if (error) nslog(@"failure serialize json object %@", error); nsurl *url = [nsurl urlwithstring:palurl]; nsmutableurlrequest* request = [nsmutableurlrequest requestwithurl:url cachepolicy:nsurlrequestuseprotocolcachepolicy timeoutinterval:timeoutinterval]; [request sethttpmethod:@"post"]; [request setvalue:@"application/x-www-form-urlencoded" forhttpheaderfield:@"content-type"]; [request setvalue:@"application/json" forhttpheaderfield:@"accept"]; [request sethttpbody:postdata]; [nsurlconnection sendasynchronousrequest:request queue:[nsoperationqueue mainqueue] completionhandler: ^(nsurlresponse *response, nsdata *data, nserror *connectionerror) { if (data) { nsmutabledictionary *responsedict = [nsjsonserialization jsonobjectwithdata:data options:0 error:nil]; nslog(@"uploaded location response = %@",responsedict); } else { nslog(@"connectionerror===%@",connectionerror); } }];
Comments
Post a Comment