iPhones OS: how to programmatically differentiate iPad 3G from iPad Wi-Fi?

前端 未结 2 1618
南方客
南方客 2021-02-14 11:28

Is there any property or other mechanism in iPhone OS to check during runtime whether application is running on iPad 3G or iPad Wi-Fi? Seems like UIDevice class does not provide

2条回答
  •  春和景丽
    2021-02-14 12:10

    You can differentiate between WiFi and 3G iPads if your app is running on a second generation iPad:

    + (NSString *) iPadModelName 
    {
        size_t size;
        sysctlbyname("hw.machine", NULL, &size, NULL, 0);
        char *machine = malloc(size);
        sysctlbyname("hw.machine", machine, &size, NULL, 0);
        NSString *platform = [NSString stringWithCString:machine encoding:NSASCIIStringEncoding];
        free(machine);
        if ([platform isEqualToString:@"iPad2,1"])      return @"iPad 2 (WiFi)";
        if ([platform isEqualToString:@"iPad2,2"])      return @"iPad 2 (GSM)";
        if ([platform isEqualToString:@"iPad2,3"])      return @"iPad 2 (CDMA)";
    
        return platform;
    }
    

提交回复
热议问题