1

In my app i am trying to get network status using NetworkReachability. I tried it when i am under wifi or 3g connection and it works perfectly.

The problem is when i am connected to a personal hotspot/tethering(tested with iPhone to iPhone, Android to iPhone and routers with sim) i get always 3g connection and not wifi.Tested with ios10. Is there any way without using private framework to control if i am under tethering connection or hotspot?

simas
  • 222
  • 1
  • 8

2 Answers2

0

You have check Reachability for internet, Using following link to download Reachability demo project from Apple:

https://developer.apple.com/library/content/samplecode/Reachability/Introduction/Intro.html

,and add both .h and .m files to your project.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNetworkChange:) name:kReachabilityChangedNotification object:nil];

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

- (void) handleNetworkChange:(NSNotification *)notice
{

  NetworkStatus remoteHostStatus = [reachability currentReachabilityStatus];

   if(remoteHostStatus == NotReachable) {NSLog(@"no");}
else if (remoteHostStatus == ReachableViaWiFi) {NSLog(@"wifi"); }
else if (remoteHostStatus == ReachableViaWWAN) {NSLog(@"cell"); }
}
PT Vyas
  • 722
  • 9
  • 31
0

In GitHub, AFNetworking library provide the check the network Reachability status. Using the Network Reachability Manager object file to detect the status of internet reachability status.

Shared Network Reachability

[[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
    NSLog(@"Reachability: %@", AFStringFromNetworkReachabilityStatus(status));
}];

[[AFNetworkReachabilityManager sharedManager] startMonitoring];
PT Vyas
  • 722
  • 9
  • 31