zoukankan      html  css  js  c++  java
  • iOS

    1.这种是在较高层次获取设备类型,返回的是 iPhone , iPod , iPad 。适合要求不高的。

    NSString *deviceType = [[UIDevice currentDevice] model];



    2.这是Linux中获取设备类型的方法,主要是C语言的方法,注意引入头文件 #include 。输入底层获取设备类型的方法。

    #include 
    
    - (NSString *)getDeviceVersionInfo
    {
        size_t size;
        // get the length of machine name
        sysctlbyname("hw.machine", NULL, &size, NULL, 0);
        // get machine name
        char *machine = malloc(size);
        sysctlbyname("hw.machine", machine, &size, NULL, 0);
        NSString *platform = [NSString stringWithFormat:@"%s", machine];
        free(machine);
        
        return platform;
    }
    
    -(NSString *)correspondVersion
    {
        NSString *correspondVersion = [self getDeviceVersionInfo];
        
        if ([correspondVersion isEqualToString:@"i386"])        return@"Simulator";
        if ([correspondVersion isEqualToString:@"x86_64"])       return @"Simulator";
        
        if ([correspondVersion isEqualToString:@"iPhone1,1"])   return@"iPhone 1";
        if ([correspondVersion isEqualToString:@"iPhone1,2"])   return@"iPhone 3";
        if ([correspondVersion isEqualToString:@"iPhone2,1"])   return@"iPhone 3S";
        if ([correspondVersion isEqualToString:@"iPhone3,1"] || [correspondVersion isEqualToString:@"iPhone3,2"])   return@"iPhone 4";
        if ([correspondVersion isEqualToString:@"iPhone4,1"])   return@"iPhone 4S";
        if ([correspondVersion isEqualToString:@"iPhone5,1"] || [correspondVersion isEqualToString:@"iPhone5,2"])   return @"iPhone 5";
        if ([correspondVersion isEqualToString:@"iPhone5,3"] || [correspondVersion isEqualToString:@"iPhone5,4"])   return @"iPhone 5C";
        if ([correspondVersion isEqualToString:@"iPhone6,1"] || [correspondVersion isEqualToString:@"iPhone6,2"])   return @"iPhone 5S";
        
        if ([correspondVersion isEqualToString:@"iPod1,1"])     return@"iPod Touch 1";
        if ([correspondVersion isEqualToString:@"iPod2,1"])     return@"iPod Touch 2";
        if ([correspondVersion isEqualToString:@"iPod3,1"])     return@"iPod Touch 3";
        if ([correspondVersion isEqualToString:@"iPod4,1"])     return@"iPod Touch 4";
        if ([correspondVersion isEqualToString:@"iPod5,1"])     return@"iPod Touch 5";
        
        if ([correspondVersion isEqualToString:@"iPad1,1"])     return@"iPad 1";
        if ([correspondVersion isEqualToString:@"iPad2,1"] || [correspondVersion isEqualToString:@"iPad2,2"] || [correspondVersion isEqualToString:@"iPad2,3"] || [correspondVersion isEqualToString:@"iPad2,4"])     return@"iPad 2";
        if ([correspondVersion isEqualToString:@"iPad2,5"] || [correspondVersion isEqualToString:@"iPad2,6"] || [correspondVersion isEqualToString:@"iPad2,7"] )      return @"iPad Mini";
        if ([correspondVersion isEqualToString:@"iPad3,1"] || [correspondVersion isEqualToString:@"iPad3,2"] || [correspondVersion isEqualToString:@"iPad3,3"] || [correspondVersion isEqualToString:@"iPad3,4"] || [correspondVersion isEqualToString:@"iPad3,5"] || [correspondVersion isEqualToString:@"iPad3,6"])      return @"iPad 3";
        
        return correspondVersion;
    }





    3.这是2一样,是Linux中获取设备类型的方法,主要是C语言的方法,注意引入头文件 #import "sys/utsname.h" 。输入底层获取设备类型的方法。

    #import "sys/utsname.h"
    
    - (NSString *)getDeviceVersionInfo
    {
        struct utsname systemInfo;
        uname(&systemInfo);
        NSString *platform = [NSString stringWithFormat:@"%s", systemInfo.machine];
        
        return platform;
    }
    
    -(NSString *)correspondVersion
    {
        NSString *correspondVersion = [self getDeviceVersionInfo];
        
        if ([correspondVersion isEqualToString:@"i386"])        return@"Simulator";
        if ([correspondVersion isEqualToString:@"x86_64"])       return @"Simulator";
        
        if ([correspondVersion isEqualToString:@"iPhone1,1"])   return@"iPhone 1";
        if ([correspondVersion isEqualToString:@"iPhone1,2"])   return@"iPhone 3";
        if ([correspondVersion isEqualToString:@"iPhone2,1"])   return@"iPhone 3S";
        if ([correspondVersion isEqualToString:@"iPhone3,1"] || [correspondVersion isEqualToString:@"iPhone3,2"])   return@"iPhone 4";
        if ([correspondVersion isEqualToString:@"iPhone4,1"])   return@"iPhone 4S";
        if ([correspondVersion isEqualToString:@"iPhone5,1"] || [correspondVersion isEqualToString:@"iPhone5,2"])   return @"iPhone 5";
        if ([correspondVersion isEqualToString:@"iPhone5,3"] || [correspondVersion isEqualToString:@"iPhone5,4"])   return @"iPhone 5C";
        if ([correspondVersion isEqualToString:@"iPhone6,1"] || [correspondVersion isEqualToString:@"iPhone6,2"])   return @"iPhone 5S";
        
        if ([correspondVersion isEqualToString:@"iPod1,1"])     return@"iPod Touch 1";
        if ([correspondVersion isEqualToString:@"iPod2,1"])     return@"iPod Touch 2";
        if ([correspondVersion isEqualToString:@"iPod3,1"])     return@"iPod Touch 3";
        if ([correspondVersion isEqualToString:@"iPod4,1"])     return@"iPod Touch 4";
        if ([correspondVersion isEqualToString:@"iPod5,1"])     return@"iPod Touch 5";
        
        if ([correspondVersion isEqualToString:@"iPad1,1"])     return@"iPad 1";
        if ([correspondVersion isEqualToString:@"iPad2,1"] || [correspondVersion isEqualToString:@"iPad2,2"] || [correspondVersion isEqualToString:@"iPad2,3"] || [correspondVersion isEqualToString:@"iPad2,4"])     return@"iPad 2";
        if ([correspondVersion isEqualToString:@"iPad2,5"] || [correspondVersion isEqualToString:@"iPad2,6"] || [correspondVersion isEqualToString:@"iPad2,7"] )      return @"iPad Mini";
        if ([correspondVersion isEqualToString:@"iPad3,1"] || [correspondVersion isEqualToString:@"iPad3,2"] || [correspondVersion isEqualToString:@"iPad3,3"] || [correspondVersion isEqualToString:@"iPad3,4"] || [correspondVersion isEqualToString:@"iPad3,5"] || [correspondVersion isEqualToString:@"iPad3,6"])      return @"iPad 3";
        
        return correspondVersion;
  • 相关阅读:
    Linux LCD驱动(四)--驱动的实现
    Linux LCD驱动(三)--图形显示
    s3c2440的LCD字符显示
    Linux framebuffer显示bmp图片
    Linux Framebuffer编程简介
    linux 2440 LCD 应用程序编程
    嵌入式Linux下S3C2410的调色板彩色显示
    l​i​n​u​x​下​L​C​D​(​f​r​a​m​e​b​u​f​f​e​r​)​驱​动​分​析
    我的基本信息
    unity生命周期
  • 原文地址:https://www.cnblogs.com/liaolijun/p/6682140.html
Copyright © 2011-2022 走看看