zoukankan      html  css  js  c++  java
  • 01-12 IOS获取手机与屏幕属性


    在次之前,补充个内容。UIDevice是无法获得具体的设备型号的。

    要获得设备型号,比如(iphone 4s, iphone5)这样的,要通过这样的办法。

    1.引入头文件。

    #include <sys/types.h>

    #include <sys/sysctl.h>

    2.获取型号

                //手机型号。
                size_t size;
                sysctlbyname("hw.machine", NULL, &size, NULL, 0);
                char *machine = (char*)malloc(size);
                sysctlbyname("hw.machine", machine, &size, NULL, 0);
                NSString *platform = [NSString stringWithCString:machine 
                                      encoding:NSUTF8StringEncoding];

    这里得到的platform是个设备型号。  比如iphone5,2.

    所以如果想更完美点,可以自己根据字符串判断。

    比如: if ([platform isEqualToString:@"iPhone3,1"])    return @"iPhone 4";

     

    一.UIDevice

        //设备相关信息的获取  
        NSString *strName = [[UIDevice currentDevice] name];  
        NSLog(@"设备名称:%@", strName);//e.g. "My iPhone"  
    
        NSString *strId = [[UIDevice currentDevice] uniqueIdentifier];  
        NSLog(@"设备唯一标识:%@", strId);//UUID,5.0后不可用  
          
        NSString *strSysName = [[UIDevice currentDevice] systemName];  
        NSLog(@"系统名称:%@", strSysName);// e.g. @"iOS"  
    
        NSString *strSysVersion = [[UIDevice currentDevice] systemVersion];  
        NSLog(@"系统版本号:%@", strSysVersion);// e.g. @"4.0"  
          
        NSString *strModel = [[UIDevice currentDevice] model];  
        NSLog(@"设备模式:%@", strModel);// e.g. @"iPhone", @"iPod touch"  
          
        NSString *strLocModel = [[UIDevice currentDevice] localizedModel];  
        NSLog(@"本地设备模式:%@", strLocModel);// localized version of model 
        //地方型号(国际化区域名称)  
          
        NSString* phoneModel = [[UIDevice currentDevice] model];  
        NSLog(@"手机型号: %@",phoneModel );   //手机型号
  • 相关阅读:
    阿里SRE体系如何支撑24小时峰值压力、220+个国家“剁手党”?
    《算法技术手册》一2.4.4 线性算法的性能
    8月7日云栖精选夜读:五分钟读懂SIGIR 2017前沿技术研究成果
    作业9 DFA最小化,语法分析初步
    作业8 非确定的自动机NFA确定化为DFA
    作业7 正规式、正规文法与自动机
    作业6 正规文法与正规式
    作业5 词法分析程序的设计与实现
    作业4 文法和语言总结与梳理
    作业3 语法树,短语,直接短语,句柄
  • 原文地址:https://www.cnblogs.com/gzz2016/p/5123743.html
Copyright © 2011-2022 走看看