Checking the Internet Connection iOS App -
in splash screen subscribe uiapplicationdidbecomeactivenotification.
- (void)viewdidload { [super viewdidload]; // register notifications [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(checkinternetconnection:) name:uiapplicationdidbecomeactivenotification object:nil]; } -(void) checkinternetconnection:(nsnotification *) notification { internetstatus = [[reachability reachabilityforinternetconnection] currentreachabilitystatus]; if(internetstatus == notreachable) { [apphelper showalert:@"error" message:@"error downloading data. please check network connection , try again." cancelbuttontitle:nil otherbuttontitles:@[@"ok"]]; return; } [self viewdidappear:yes]; } - (void)viewdidappear:(bool)animated { [super viewdidappear:animated]; if(!(internetstatus == notreachable)) { appdelegate *applicationdelegate = (appdelegate*)[[uiapplication sharedapplication] delegate]; [applicationdelegate performselector:@selector(showmainmenu) withobject:[nsnumber numberwithbool:yes] afterdelay:3.0]; } }
the problem internet connection checked on splash screen if in middle of other screen , loose internet connectivity there no way tell connection has been gone. how can make logic check client's internet connection.
you want use reachability library allows callbacks changes (like one).
then, in each controller requires it, create reachability instance , set reachableblock
, unreachableblock
perform required actions.
Comments
Post a Comment