Search code examples
iphoneobjective-ciosuidevicecellular-network

Know if iOS device has cellular data capabilities


I have a toggle in my app that's "download on WiFi only". However, that toggle is useless for iPod touch or WiFi-iPads.

Is there a way to know if the device has cellular data capabilities in code? Something that would work in the future would be great too (like if an iPod touch 5th gen with 3G comes out).


Solution

  • Hi you should be able to check if it has the pdp_ip0 interface

    #import <ifaddrs.h>
    
    - (bool) hasCellular {
        struct ifaddrs * addrs;
        const struct ifaddrs * cursor;
        bool found = false;
        if (getifaddrs(&addrs) == 0) {
            cursor = addrs;
            while (cursor != NULL) {
                NSString *name = [NSString stringWithUTF8String:cursor->ifa_name];
                if ([name isEqualToString:@"pdp_ip0"]) {
                    found = true;
                    break;
                }
                cursor = cursor->ifa_next;
            }
            freeifaddrs(addrs);
        }
        return found;
    }
    

    This doesn't use any private APIs.