ios - AFNetworking returns no connection despite internet connectivity -


i'm using afnetworking determine whether user has internet connection. returns false on both wifi , 4g lte , have checked make sure they're operational. have following code:

-(void)viewdidload{  [[afnetworkreachabilitymanager sharedmanager] startmonitoring];          if ([self connected])         [self dosomething];      else         [self noconnection]; }  - (bool)connected {      nslog(@"this returns 0 %hhd", [afnetworkreachabilitymanager sharedmanager].reachable);      return [afnetworkreachabilitymanager sharedmanager].reachable; }  -(void)noconnection{     uialertview *alert = [[uialertview alloc] initwithtitle:@"no internet!"                                                 message:@"sorry, don't have internet      connection @ time.  please try again later."                                                delegate:self                                       cancelbuttontitle:@"ok"                                       otherbuttontitles:nil];      [alert show];   } 

this not solution using afnetworking using sample code apple

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]){  //connected! } else{   //not connected internet! } 

very important

if project not using arc

  • go target >
  • build phase >
  • double click reachability file
  • add -fno-objc-arc

hope helps


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -