Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reachability Class not working properly for VPN connection

I am working on an application which needs VPN connection for Data Synchronization. I am using reachability class to check the Host availability.
@Functionality :- When app is connected to VPN through Junos Pulse app, data synchronization should proceed if VPN connection is lost it should throw the Alert message. Now it is working for the scenario given below.
@Working scenario :- VPN is connected initially, i completed the sync and then disconnected the VPN manually from Junos Pulse. Now i am trying to sync again it is throwing alert which is expected.
@Problem Scenarion :- I completed the sync initially and left the app idle to get VPN disconnected automatically. Now after VPN gone i am trying to sync again. It does not through the alert that VPN not there. It attempts the sync functionality and fails as server is not accessible without VPN.

I am exhausted by searching it's solution on internet. I am pasting my Code snippet here. Any suggestion is highly appreciated.

-(BOOL)checkHostAvailability
{   
Reachability *objReach = [Reachability reachabilityWithHostName:[self hostServer]];
NetworkStatus hostAvailability = [objReach currentReachabilityStatus];
if(hostAvailability == ReachableViaWiFi || hostAvailability == ReachableViaWWAN) {
    RLog(@"Host is Reachable");
    return YES;
}
return NO;
}
like image 613
Gandalf Avatar asked Jul 11 '12 08:07

Gandalf


1 Answers

It seems like there's a bug in iOS. When you connect VPN using cellular connection(or WiFi) and then switch to WiFi(or cellular), the system doesn't detect this. Reachability won't post any notification because iOS still thinks you haven't switched your interface.

I managed to reproduce it, in the following way:

  1. Connected VPN on 3G, with on demand disabled, using NetworkExtension framework.
  2. Switched to WiFi Network.
  3. Plugged off the ethernet cable from WiFI router, so router can’t share Internet.
  4. Checked if there’s Internet on the device with active VPN.

And it was there. This means , that all traffic comes through the cellular network.

like image 169
Timur Suleimanov Avatar answered Oct 13 '22 12:10

Timur Suleimanov