multithreading - Application UI hangs due to networking , iOS -
i developing ios application implementing push notifications.
in appdelegate , more in didregisterforremotenotificationswithdevicetoken function , after register push notifications , make http post request send server users credentials (cfuuid , os , etc..) , push token.
when server app goes smoothly. however , if reason server unreachable ui of application hangs around 30 seconds (till connection timeout) , thing see white screen.
how separate "networking" ui ? guess answer using thread.
how ? thing doing inside didregisterforremotenotificationswithdevicetoken use asihttprequest library send credentials server.
the code needs executed in different thread looks :
nsstring *jsonstring; //jsonstring = [[nsstring alloc] initwithformat:@"{\"deviceuuid\":\"%@\",\"os\":\"ios\", \"active\":\"%d\", \"pushtoken\":\"%@\"}",deviceuuid,active,token]; jsonstring = [[nsstring alloc] initwithformat:@"{\"deviceuuid\":\"%@\",\"os\":\"ios\", \"pushtoken\":\"%@\"}",deviceuuid,token]; nslog(@"%@",jsonstring); //nsstring *urlstr= [[nsstring alloc] initwithformat:cityinfo_server_url,@"push_notifications/register"]; nsstring *urlstr= [[nsstring alloc] initwithformat:cityinfo_server_url,@"register.php"]; //send json file , using asihttpclass nsurl *url = [nsurl urlwithstring:urlstr]; asihttprequest *request = [asihttprequest requestwithurl:url]; request.timeoutseconds = time_out_seconds; [request setrequestmethod:@"put"]; //nsstring *credentials= [self encodecredentials]; //[request addrequestheader:@"authorization" value:[[nsstring alloc] initwithformat:@"basic %@",credentials]]; [request addrequestheader:@"content-type" value:@"application/json; charset=utf-8"]; [request appendpostdata:[jsonstring datausingencoding:nsutf8stringencoding]]; [request startsynchronous]; if([request responsestatuscode]==200){ nslog(@"server reached. response status : 200"); return true; } else { nslog(@"server not reached"); return false;
instead of sending synchronous request send asynchronous request
[request startasynchronous]; and call method hitting service after time interval delegate method.
Comments
Post a Comment