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