ios - add 3G detection to the following code -


i have method checks wi-fi got old project had, need make check 3g or wifi, , if none available give error message.

original sample working:

- (bool)checkforwificonnection {      reachability* wifireach = [reachability reachabilityforlocalwifi];     networkstatus netstatus = [wifireach currentreachabilitystatus];     if (netstatus!=reachableviawifi)     {         uialertview *alertview = [[uialertview alloc] initwithtitle:nslocalizedstring(@"sem conexão à internet!", @"alertview")                                                             message:nslocalizedstring(@"não está conectado à internet. tente novamente após se connectar.", @"alertview")                                                            delegate:self                                                   cancelbuttontitle:nslocalizedstring(@"ok", @"alertview")                                                   otherbuttontitles: nil];         [alertview show];         return no;     }     else {         return yes;     } } 

how make check reachableviawwan ? can add here (<-) ??

- (bool)checkforwificonnection {          reachability* wifireach = [reachability reachabilityforlocalwifi];         networkstatus netstatus = [wifireach currentreachabilitystatus];         if (netstatus!=reachableviawifi && reachableviawwan) <- (i error saying use of logical && constant operand)         {             uialertview *alertview = [[uialertview alloc] initwithtitle:nslocalizedstring(@"sem conexão à internet!", @"alertview")                                                                 message:nslocalizedstring(@"não está conectado à internet. tente novamente após se connectar.", @"alertview")                                                                delegate:self                                                       cancelbuttontitle:nslocalizedstring(@"ok", @"alertview")                                                       otherbuttontitles: nil];             [alertview show];             return no;         }         else {             return yes;         }     } 

thanks help.

simply change:

reachability* wifireach = [reachability reachabilityforlocalwifi]; 

to:

reachability* wifireach = [reachability reachabilityforinternetconnection]; 

and

if (netstatus!=reachableviawifi) 

to:

if (netstatus == notreachable) 

in other words:

reachability* wifireach = [reachability reachabilityforinternetconnection]; networkstatus netstatus = [wifireach currentreachabilitystatus]; if (netstatus == notreachable) { 

btw - please consult objective-c tutorial learn how write compound expressions. if statement need like:

if (netstatus!=reachableviawifi && netstatus!=reachableviawwan) 

but while solve compiler issue, won't work code because wwan value won't ever given when using reachabilityforlocalwifi.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -