zoukankan      html  css  js  c++  java
  • 获取设备版本

    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

        UIDevice提供了多种属性、类函数及状态通知,帮助我们全方位了解设备状况。从检测电池电量到定位设备与临近感应,UIDevice所做的工作就是为应用程序提供用户及设备的一些信息。UIDevice类还能够收集关于设备的各种具体细节,例如机型及iOS版本等。其中大部分属性都对开发工作具有积极的辅助作用。下面的代码简单的使用UIDevice获取手机属性。


    //    [[UIDevice currentDevice] systemName]; // 系统名
    //    [[UIDevice currentDevice] systemVersion]; //版本号
    //    [[UIDevice currentDevice] model]; //类型,模拟器,真机
    //    [[UIDevice currentDevice] uniqueIdentifier]; //唯一识别码
    //    [[UIDevice currentDevice] name]; //设备名称
    //    [[UIDevice currentDevice] localizedModel]; // 本地模式
        //设备相关信息的获取
        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 );   //手机型号
    

    二。NSBundle


    bundle是一个目录,其中包含了程序会使用到的资源. 这些资源包含了如图像,声音,编译好的代码,nib文件(用户也会把bundle称为plug-in). 对应bundle,cocoa提供了类NSBundle.一个应用程序看上去和其他文件没有什么区别. 但是实际上它是一个包含了nib文件,编译代码,以及其他资源的目录. 我们把这个目录叫做程序的main bundle。通过这个路径可以获取到应用的信息,例如应用名、版本号等。
        //app应用相关信息的获取
        NSDictionary *dicInfo = [[NSBundle mainBundle] infoDictionary];
        // CFShow(dicInfo);
        
        NSString *strAppName = [dicInfo objectForKey:@"CFBundleDisplayName"];
        NSLog(@"App应用名称:%@", strAppName);   // 当前应用名称
        
        NSString *strAppVersion = [dicInfo objectForKey:@"CFBundleShortVersionString"];
        NSLog(@"App应用版本:%@", strAppVersion);    // 当前应用软件版本  比如:1.0.1  
        
        NSString *strAppBuild = [dicInfo objectForKey:@"CFBundleVersion"];
        NSLog(@"App应用Build版本:%@", strAppBuild);      // 当前应用版本号码   int类型
    

    三。NSLocale


    NSLocale可以获取用户的本地化信息设置,例如货币类型,国家,语言,数字,日期格式的格式化,提供正确的地理位置显示等等。下面的代码获取机器当前语言和国家代码。
        //Getting the User’s Language
        NSArray *languageArray = [NSLocale preferredLanguages];
        NSString *language = [languageArray objectAtIndex:0];
        NSLog(@"语言:%@", language);//en
        
        NSLocale *locale = [NSLocale currentLocale];
        NSString *country = [locale localeIdentifier];
        NSLog(@"国家:%@", country); //en_US
    
  • 相关阅读:
    World Wind Java开发之一(转)
    Excel如何显示隐藏列?
    Oracle开发›如何取出每个分组的第一条记
    如何解决EXCEL中的科学计数法
    使用POI 读取 Excel 文件,读取手机号码 变成 1.3471022771E10
    POI读取单元格信息及单元格公式
    java中判断字符串是否为数字的方法的几种方法
    阿里云OSS的 存储包、下行流量包、回流流量包 三者有啥关系
    vue+datatable+vue-resource动态获取jsonp数据2
    vue+datatable+vue-resource动态获取jsonp数据
  • 原文地址:https://www.cnblogs.com/likun123/p/3960228.html
Copyright © 2011-2022 走看看