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
Post a Comment