uitableview - Reachability iOS -


i have tableview recieves data server method call retrievedata. use reachability test if user has internet connection. if yes retrievedata called. if not nslog printed.

all works fine, but.. if has connection, table takes few second load , that's not want. how can immediately?

i check connection in viewdidload method.

- (void)viewdidload {     [super viewdidload];      reachability* reach = [reachability reachabilitywithhostname:@"www.google.com"];      reach.reachableblock = ^(reachability*reach)     {         // load table content         [self retrievedata];     };      reach.unreachableblock = ^(reachability*reach)     {         nslog(@"no internet");     };      [reach startnotifier];  } 

even though google site "most likely" won't go down, in theory bad idea rely on reachability of hostname determine connectivity.

once have downloaded , imported reachbility.m , reachbility.h files

create helper function:

-(bool)isconnected{   reachability *reachability = [reachability reachabilityforinternetconnection];   networkstatus networkstatus = [reachability currentreachabilitystatus];    return !(networkstatus == notreachable);     } 

then use it

if([self isconnected]){  [self retrievedata]; } else{   //not connected internet! } 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -