Need some help here.
I need to detect if an iOS device have (on a certain moment) cellular capabilities (No matter which one).
I tried to use reachability class, but the problem start when the user is connected to WiFi, because if so - reachability can't detect cellular
I also tried to use this code:
CTTelephonyNetworkInfo *telephonyInfo = [CTTelephonyNetworkInfo new];
NSLog(@"Current Radio Access Technology: %@", telephonyInfo.currentRadioAccessTechnology);
[NSNotificationCenter.defaultCenter addObserverForName:CTRadioAccessTechnologyDidChangeNotification
object:nil
queue:nil
usingBlock:^(NSNotification *note)
{
NSLog(@"New Radio Access Technology: %@", telephonyInfo.currentRadioAccessTechnology);
}];
But even if I'm turning off cellular data its returning CTRadioAccessTechnologyLTE
i can't understand why.
Edit
I tried to enumerate the network interface like the suggastion in the answer below, but the pdp_ip0 is still up and getting an IP.
struct ifaddrs* interfaces = NULL;
struct ifaddrs* temp_addr = NULL;
// retrieve the current interfaces - returns 0 on success
NSInteger success = getifaddrs(&interfaces);
if (success == 0)
{
// Loop through linked list of interfaces
temp_addr = interfaces;
while (temp_addr != NULL)
{
NSString* name = [NSString stringWithUTF8String:temp_addr->ifa_name];
NSString *address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
NSLog(@" Name:%@ IP:%@",name,address);
temp_addr = temp_addr->ifa_next;
}
}
// Free memory
freeifaddrs(interfaces);
Output on cell disable:
2015-08-04 11:58:33.297 check[405:46916] Name:pdp_ip0 IP:255.7.0.0
Output on cell enabled (the pdp_ip0 appear twice)
2015-08-04 11:59:08.914 check[405:46916] Name:pdp_ip0 IP:255.7.0.0
2015-08-04 11:59:08.914 check[405:46916] Name:pdp_ip0 P:10.130.112.****)
I dont want to realay on it appearing twice, is there a better way?
Can anyone can have any idea how can I get this to work? (without using hidden API).
Thanks a lot.