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 cl
If anyone needs - this solution I wrote:
- (BOOL)isHaveCell{
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];
if ([name isEqualToString:@"pdp_ip0"] && temp_addr->ifa_addr->sa_family ==2 ) {
return TRUE;
}
temp_addr = temp_addr->ifa_next;
}
}
// Free memory
freeifaddrs(interfaces);
return FALSE;
}
You can get that info by enumerating network interfaces. Cellular interface is named pdp_ip0
. When cellular interface is active and cellular data is enabled it will be up and have an IP address. When you disable cellular data (or don't have cellular connection at all) interface will be down.
UPDATE
I will say again, please read my answers carefully. Check IFF_UP
, otherwise you're checking non-active interfaces. pdp_ip0
appears twice because one is IPv4 and other is IPv6 - you need to check ifa_addr->sa_family
. 255.7.0.0
is a garbage value because that's not a proper way to retrieve an IPv6 address - you need to use inet_ntop
. If you do everything correctly then your problem will be solved. Or just try reading documentation - that's all basic well-known APIs that's covered everywhere on the internet.
Your output exactly matches what I'm seeing on my device:
pdp_ip0
interface but it's downpdp_ip0
interfaces - first is IPv6, second is IPv4. Both of them will be up