2

I am working on an iPad app which requires frequent connections to a publicly hosted webserver. I have a Wi-Fi network which requires authentication and gets timed out after 30 minutes of logging in.

I am using the Reachability class but I am not able to get the Network Awareness that I want in my app. The Reachability class takes care whenever the user connects/disconnects from the Wi-Fi network, but in case of authentication time out, the Reachability class is giving me wrong results.

Reachability *internetReach=[Reachability reachabilityWithHostName:@"www.google.com"];

if ([internetReach currentReachabilityStatus] == NotReachable) {
    [self alertMessage:@"Wi-Fi connection not available"];
}

I do not get the intended alert message when the Wi-Fi has timed out. What I need is that my app should recognize that Wi-Fi has been timed out and it should bring up the Safari Wi-Fi authentication sheet automatically for the user (like it happens in App Store, YouTube, etc.)

tanamania
  • 51
  • 1
  • 5

1 Answers1

1

I think you are missing some code. First you must start the notifier and then you need to store the Reachabilityreference, e.g. as a property. Then you need to implement the notification method. After the change, your code could look something like this:

-(void)viewWillAppear:(BOOL)animated {
    Reachability *internetReach=[Reachability reachabilityWithHostName:@"www.google.com"];
    [internetReach startNotifier];

    self.internetReachable = internetReach;
}

-(void)checkNetworkStatus:(NSNotification*)notice;
{
    NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];

    if ([internetReachable currentReachabilityStatus] == NotReachable) {
        [self alertMessage:@"Wi-Fi connection not available"];
    }
}
Johan Karlsson
  • 1,136
  • 1
  • 14
  • 37
  • this post doesn't answer OPs question. – Andrey Zverev Feb 07 '12 at 08:34
  • Why not? He is asking why he is not getting an alert view. As a developer you must yourself show an alertview when you are getting a call to checkNetworkStatus. In his example he is not getting any alertview. The code he has provided is not correct. – Johan Karlsson Feb 07 '12 at 08:36
  • Maybe I'm missing something, but as far as I understand, he wants to bring up Wi-Fi authentication screen, not to show an alertView. – Andrey Zverev Feb 07 '12 at 08:44
  • 1
    Maybe I misunderstood the question!? Then his code is a little bit misleading, since the code is for Internet reachability. – Johan Karlsson Feb 07 '12 at 08:48
  • Can you tell what actually is the checkNetworkStatus: method? From where would it get called? I do not want to add an observer for the kReachabilityChangedNotification. What I need is an on-demand network status. My code gives me accurate results in all cases except for the case when I am connected to Wi-Fi but am not authenticated. My UIAlertView is in the alertMessage: method, actual body of which is irrelevant here. @AndreyZ. You are right. I need to bring up the Safari authentication sheet which I get in all Apple apps like YouTube, AppStore, Mail, etc. – tanamania Feb 09 '12 at 11:30
  • 1
    I got part of my problem solved. For bringing up the Safari authentication sheet, I just had to include the "Application Uses Wi-Fi" property and set it to YES in the Info.plist file. The other part of detecting authentication timeout is still a problem. – tanamania Mar 08 '12 at 11:26