2

I'm using Tony Million's Reachability for displaying a UIAlertView if the device is not connected to the internet. It works almost correctly, but not perfect on iOS8. Fortunately I'm using the PubNub SDK and I discovered PNReachability class during my test session in the console that has a checkServiceAvailable: instance method which could do the same job as I think. Possibly somebody could confirm me that I'm right? Or is there any trick to check the internet connection with the PubNub SDK? As I discovered PNReachability works also after I call [PubNub disconnect] or before [PubNub connect] so it would be amazing for displaying "No Internet Connection" alerts across a project..

I would really appreciate any tips or guidance, using PubNub for this would make my life much easier, it's a really cool stuff you can trust in.

Alex Cio
  • 6,014
  • 5
  • 44
  • 74
rihekopo
  • 3,241
  • 4
  • 34
  • 63

1 Answers1

1

Imported inside your project, you can check connectivity like this:

Reachability *reachability = [Reachability reachabilityForInternetConnection];
[reachability startNotifier];

NetworkStatus status = [reachability currentReachabilityStatus];

if(status == NotReachable) 
{
    //No internet
}
else if (status == ReachableViaWiFi)
{
    //WiFi
}
else if (status == ReachableViaWWAN) 
{
    //3G
}

Using a specific URL for your request you can check if there is a connection to exactly this URL

Reachability *reach = [Reachability reachabilityWithHostname:gameApiHost];
Alex Cio
  • 6,014
  • 5
  • 44
  • 74