iOS verifica si la tecnología celular está disponible incluso si el dispositivo está conectado a WiFi
Necesito ayuda aquí.
Necesito detectar si un dispositivo iOS tiene (en un momento determinado) capacidades celulares (sin importar cuál).
Traté de usar la clase de accesibilidad, pero el problema comienza cuando el usuario está conectado a WiFi, porque si es así, la accesibilidad no puede detectar celulares
También intenté usar este código:
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);
}];
Pero incluso si apago los datos celulares, regresaCTRadioAccessTechnologyLTE
No puedo entender por qué.
Editar
Traté de enumerar la interfaz de red como la sugerencia en la respuesta a continuación, pero el pdp_ip0 todavía está activo y obteniendo una 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);
Salida en celda deshabilitada:
2015-08-04 11:58:33.297 check[405:46916] Name:pdp_ip0 IP:255.7.0.0
Salida en celda habilitada (pdp_ip0 aparece dos veces)
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.****)
No quiero volver a aparecer apareciendo dos veces, ¿hay una mejor manera?
¿Alguien puede tener alguna idea de cómo puedo hacer que esto funcione? (sin usar API oculta).
Muchas gracias.