alert - How to solve internet check problem in iPhone? -
alert - How to solve internet check problem in iPhone? -
i working on application , have check net connectivity. using 2 files reachability.h , reachability.m. have show alert when net not working.
but when observer check net shows alert view more 1 time. , times shows alert more 9-10 times. code here:
in .h file
reachability* internetreachable; reachability* hostreachable; networkstatus internetstatus;
in .m file
internetreachable = [[reachability reachabilityforinternetconnection] retain]; [internetreachable startnotifier]; [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(checknetworkstatus:) name:kreachabilitychangednotification object:nil]; hostreachable = [[reachability reachabilitywithhostname: @"www.apple.com"] retain]; [hostreachable startnotifier]; - (void) checknetworkstatus:(nsnotification *)notice { internetstatus = [internetreachable currentreachabilitystatus]; if (internetstatus != notreachable){ nslog(@"internet on"); } else { uialertview *alert = [[uialertview alloc] initwithtitle:@"error!" message:@"server not connected or down!" delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil]; [alert show]; [alert release]; internetcount++; } }
this code in delegate , using code in other classes ever have check internet
plz help
i don't utilize reachability because i've had problems you, created own implementation. import header file below , phone call [self networkisreachable]
check net connection.
#import <netinet/in.h> - (bool)networkisreachable { struct sockaddr_in zeroaddress; bzero(&zeroaddress, sizeof(zeroaddress)); zeroaddress.sin_len = sizeof(zeroaddress); zeroaddress.sin_family = af_inet; scnetworkreachabilityref defaultroutereachability = scnetworkreachabilitycreatewithaddress(null, (struct sockaddr *)&zeroaddress); scnetworkreachabilityflags flags; bool gotflags = scnetworkreachabilitygetflags(defaultroutereachability, &flags); cfrelease(defaultroutereachability); if (!gotflags) { homecoming no; } bool isreachable = flags & kscnetworkreachabilityflagsreachable; bool noconnectionrequired = !(flags & kscnetworkreachabilityflagsconnectionrequired); if ((flags & kscnetworkreachabilityflagsiswwan)) { noconnectionrequired = yes; } homecoming (isreachable && noconnectionrequired) ? yes : no; }
iphone alert reachability internet-connection
Comments
Post a Comment