• 关于UI_USER_INTERFACE_IDIOM() & UIDevice.model


    使用  UI_USER_INTERFACE_IDIOM() 进行区分  (ios 3.2 >=)  无法区分iphone和ipod
     
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
           // <define your constants here>
        } else {
          //  <define your constants here>
        }
     
    区分目前UI_USER_INTERFACE_IDIOM()有2个返回值
    UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad    
    
    UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone    
    
     
    使用 UIDevice.model 进行区分  (ios 2.0 >=)
     
        NSString *deviceType = [UIDevice currentDevice].model;
        
        if([deviceType isEqualToString:@"iPhone"]) {
            //iPhone
        }
        else if([deviceType isEqualToString:@"iPod touch"]) {
            //iPod Touch
        }
        else {
            //iPad
        }
    
     
    使用系统的一个函数sysctlbyname 来获取设备名称
    
    - (NSString *) platformString
    {
        size_t size;
        sysctlbyname("hw.machine", NULL, &size, NULL, 0);
        char *machine = malloc(size);
        sysctlbyname("hw.machine", machine, &size, NULL, 0);
        NSString *platform = [NSString stringWithUTF8String:machine];
        free(machine);
        if ([platform isEqualToString:@"iPhone1,1"])    return @"iPhone 1G";
        if ([platform isEqualToString:@"iPhone1,2"])    return @"iPhone 3G";
        if ([platform isEqualToString:@"iPhone2,1"])    return @"iPhone 3GS";
        if ([platform isEqualToString:@"iPhone3,1"])    return @"iPhone 4";
        if ([platform isEqualToString:@"iPhone3,3"])    return @"Verizon iPhone 4";
        if ([platform isEqualToString:@"iPod1,1"])      return @"iPod Touch 1G";
        if ([platform isEqualToString:@"iPod2,1"])      return @"iPod Touch 2G";
        if ([platform isEqualToString:@"iPod3,1"])      return @"iPod Touch 3G";
        if ([platform isEqualToString:@"iPod4,1"])      return @"iPod Touch 4G";
        if ([platform isEqualToString:@"iPad1,1"])      return @"iPad";
        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)";
        if ([platform isEqualToString:@"i386"])         return @"Simulator";
        return @"";
    }
    
    在添加一些收集到的
    //iPhone
        if ([deviceString isEqualToString:@"iPhone4,1"])    return @"iPhone 4S";
        if ([deviceString isEqualToString:@"iPhone5,1"])    return @"iPhone 5(AT&T)";
        if ([deviceString isEqualToString:@"iPhone5,2"])    return @"iPhone 5(GSM/CDMA)";
    //iPod Touch
        if ([deviceString isEqualToString:@"iPod5,1"])      return @"iPod Touch 5G";
    //iPad
        if ([deviceString isEqualToString:@"iPad2,5"])      return @"iPad Mini (WiFi)";
        if ([deviceString isEqualToString:@"iPad2,6"])      return @"iPad Mini (GSM)";
        if ([deviceString isEqualToString:@"iPad2,7"])      return @"iPad Mini (CDMA)";
        if ([deviceString isEqualToString:@"iPad3,1"])      return @"iPad 3 (WiFi)";
        if ([deviceString isEqualToString:@"iPad3,2"])      return @"iPad 3 (GSM)";
        if ([deviceString isEqualToString:@"iPad3,3"])      return @"iPad 3 (CDMA)";
        if ([deviceString isEqualToString:@"iPad3,4"])      return @"iPad 4 (WiFi)";
        if ([deviceString isEqualToString:@"iPad3,5"])      return @"iPad 4 (GSM)";
        if ([deviceString isEqualToString:@"iPad3,6"])      return @"iPad 4 (CDMA)";
    //Simulator
        if ([deviceString isEqualToString:@"i386"])         return @"Simulator";
        if ([deviceString isEqualToString:@"x86_64"])       return @"Simulator";
    
    
    
    转载的没有那么多个机型逐个实验.所以不敢保证都正确.
    

     原出处:http://blog.sina.com.cn/s/blog_890a737301014fim.html

  • 相关阅读:
    docker保存镜像文件
    华为云 容器获取通过LB Service访问的客户端真实IP
    maven构建指定模块和相关依赖模块
    chromium内核浏览器iframe跳转导致渲染异常
    css文本溢出省略号
    构建docker镜像部署rocketmq
    华为云软件开发平台 使用任务构建容器镜像并推送到镜像仓库
    linux ps显示完整command
    远程git仓库密码修改后idea添加remote地址或推送时报错处理
    Juqery的一些应用2—模糊查询
  • 原文地址:https://www.cnblogs.com/hualuoshuijia/p/6022744.html
Copyright © 2020-2023  润新知