获取设备型号、app信息、系统信息

</pre>一、获取设备型号的方法主要有三种:<p></p><p></p><pre name="code" class="objc"><span style="white-space:pre">	</span>///=====  设备型号:方法一  ========
        NSString * strModel  = [UIDevice currentDevice].model;
        NSLog(@"model:%@",strModel);
        NSLog(@"localizedModel: %@", [[UIDevice currentDevice] localizedModel]);
        
        //=====   设备型号:方法二 =========
        struct utsname systemInfo;
        uname(&systemInfo);
        NSString *deviceString = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
        NSLog(@"systemInfo.machine:%@",deviceString);
        
        //===== 设备型号:方法三 (model)=========
        size_t size;
        sysctlbyname ("hw.machine" , NULL , &size ,NULL ,0);
        char *model = (char *)malloc(size);
        sysctlbyname ("hw.machine" , model , &size ,NULL ,0);
        NSString * strModel3 = [NSString stringWithCString: model encoding:NSUTF8StringEncoding];
        free(model);
        NSLog(@"hw.machine-model:%@",strModel3);
        
        //===== 设备型号:方法三 (machine)=========
        char *machine = (char*)malloc(size);
        sysctlbyname("hw.machine", machine, &size, NULL, 0);
        NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
        free(machine);
        NSLog(@"hw.machine-platform:%@",platform);

输出结果:

2013-07-19 11:46:10.854 Fly Survey JS[2196:907] model:iPad

2013-07-19 11:46:10.856 Fly Survey JS[2196:907] localizedModel: iPad

2013-07-19 11:46:10.857 Fly Survey JS[2196:907] systemInfo.machine:iPad2,1

2013-07-19 11:46:10.858 Fly Survey JS[2196:907] hw.machine-model:iPad2,1

2013-07-19 11:46:10.860 Fly Survey JS[2196:907] hw.machine-platform:iPad2,1

结果中的ipad2,1这种设备标签与设备的对应关系参考:http://www.cnblogs.com/shadox/archive/2013/02/05/2893017.html

关于上面三种方法,需要注意的是:

1. 第一种方法最简单,但是只能识别是ipad、iphone还是ipod之类的,没有具体的型号

2. 第二种方法,需要导入#import <sys/utsname.h>

3. 第三种方法,需要导入
#import <sys/socket.h> 
按照结果,这里取machine和取model是一样的,没往深处研究

PS:附一段匹配的代码,给跟我一样懒的人http://blog.sina.com.cn/s/blog_67b7cb7b0101fws7.html

二、 获取app信息

参考:http://www.cnblogs.com/tx8899/archive/2012/06/18/2553690.html

 <span style="white-space:pre">	</span>//app信息
        NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
        
        //CFShow(infoDictionary);
        NSLog(@"%@", infoDictionary);
        
        // app名称
        NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];
        NSLog(@"app_Name: %@", app_Name);
        // app版本
        NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
        NSLog(@"app_Version: %@", app_Version);
        // app build版本
        NSString *app_build = [infoDictionary objectForKey:@"CFBundleVersion"];
        NSLog(@"app_build: %@", app_build);
输出结果:

2013-07-19 11:53:57.222 Fly Survey JS[2220:907] {
    BuildMachineOSBuild = 12D78;
    CFBundleDevelopmentRegion = English;
    CFBundleDisplayName = "Fly Survey JS";
    CFBundleExecutable = "Fly Survey JS";
    CFBundleExecutablePath = "/var/mobile/Applications/5FDC9EAB-23E1-4670-B226-E66BC8CCBD8C/Fly Survey JS.app/Fly Survey JS";
    CFBundleIconFile = "icon.png";
    CFBundleIconFiles =     (
        "icon.png",
        "icon@2x.png",
        "icon-72.png"
    );
    CFBundleIdentifier = "com.zhongyan.FlySurveyJS";
    CFBundleInfoDictionaryVersion = "6.0";
    CFBundleInfoPlistURL = "Info.plist -- file://localhost/var/mobile/Applications/5FDC9EAB-23E1-4670-B226-E66BC8CCBD8C/Fly%20Survey%20JS.app/";
    CFBundleName = "Fly Survey JS";
    CFBundlePackageType = APPL;
    CFBundleResourceSpecification = "ResourceRules.plist";
    CFBundleShortVersionString = "1.0.0";
    CFBundleSignature = "????";
    CFBundleSupportedPlatforms =     (
        iPhoneOS
    );
    CFBundleVersion = "1.0";
    DTCompiler = "";
    DTPlatformBuild = 10B141;
    DTPlatformName = iphoneos;
    DTPlatformVersion = "6.1";
    DTSDKBuild = 10B141;
    DTSDKName = "iphoneos6.1";
    DTXcode = 0462;
    DTXcodeBuild = 4H1003;
    LSRequiresIPhoneOS = 1;
    MinimumOSVersion = "5.0";
    NSBundleInitialPath = "/var/mobile/Applications/5FDC9EAB-23E1-4670-B226-E66BC8CCBD8C/Fly Survey JS.app";
    NSBundleResolvedPath = "/var/mobile/Applications/5FDC9EAB-23E1-4670-B226-E66BC8CCBD8C/Fly Survey JS.app";
    UIDeviceFamily =     (
        1,
        2
    );
    UIStatusBarHidden = 0;
    UISupportedInterfaceOrientations =     (
        UIInterfaceOrientationPortrait
    );
}
2013-07-19 11:53:57.225 Fly Survey JS[2220:907] app_Name: Fly Survey JS
2013-07-19 11:53:57.227 Fly Survey JS[2220:907] app_Version: 1.0.0
2013-07-19 11:53:57.229 Fly Survey JS[2220:907] app_build: 1.0

题外话,关于CFBundleVersion与CFBundleShortVersionString的说明:http://blog.sina.com.cn/s/blog_8c87ba3b0101a1gd.html

三、 系统版本、设备名称等其他信息

<span style="white-space:pre">	</span>//设备唯一id
        NSLog(@"uniqueIdentifier: %@", [[UIDevice currentDevice] uniqueIdentifier]);
        //设备名称
        NSLog(@"name: %@", [[UIDevice currentDevice] name]);
        //系统名称
        NSLog(@"systemName: %@", [[UIDevice currentDevice] systemName]);
        //系统版本
        NSLog(@"systemVersion: %@", [[UIDevice currentDevice] systemVersion]);
输出结果:

2013-07-19 12:01:16.008 Fly Survey JS[2260:907] uniqueIdentifier: 52.....................................
2013-07-19 12:01:16.012 Fly Survey JS[2260:907] name: XXXXXX
2013-07-19 12:01:16.015 Fly Survey JS[2260:907] systemName: iPhone OS
2013-07-19 12:01:16.017 Fly Survey JS[2260:907] systemVersion: 6.1.3

结果我隐藏了些,隐私嘛,大家都懂的。

另外,关于设备唯一id这个,参考另一个帖子 : http://ios.eoe.cn/thread-59076-1-1.html

四、 其他设备信息

http://blog.csdn.net/qiwancong/article/details/7914923
这里的我暂时没接触到,就不研究了,放出来以作记录。


原文地址:http://www.eoeandroid.com/forum.php?mod=viewthread&tid=494116

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值