IOS -iphone设备信息读取
Posted fei619730
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了IOS -iphone设备信息读取相关的知识,希望对你有一定的参考价值。
1.获取当前设备所有者名称:
2.获取设备的类别,是iPhone,iPod,还是iPad
这里要获取iPhone的具体类型,要有如下代码:
[objc] view plain copy
- - (NSString *)deviceString
- // 需要#import "sys/utsname.h"
- struct utsname systeminfo;
- uname(&systeminfo);
- NSString *deviceString = [NSString stringWithCString:systeminfo.machine encoding:NSUTF8StringEncoding];
- //iPhone
- if ([deviceString isEqualToString:@"iPhone1,1"]) return @"iPhone 1G";
- if ([deviceString isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";
- if ([deviceString isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS";
- if ([deviceString isEqualToString:@"iPhone3,1"]) return @"iPhone 4";
- if ([deviceString isEqualToString:@"iPhone3,2"]) return @"Verizon iPhone 4";
- if ([deviceString isEqualToString:@"iPhone4,1"]) return @"iPhone 4S";
- if ([deviceString isEqualToString:@"iPhone5,1"]) return @"iPhone 5";
- if ([deviceString isEqualToString:@"iPhone5,2"]) return @"iPhone 5";
- if ([deviceString isEqualToString:@"iPhone5,3"]) return @"iPhone 5C";
- if ([deviceString isEqualToString:@"iPhone5,4"]) return @"iPhone 5C";
- if ([deviceString isEqualToString:@"iPhone6,1"]) return @"iPhone 5S";
- if ([deviceString isEqualToString:@"iPhone6,2"]) return @"iPhone 5S";
- if ([deviceString isEqualToString:@"iPhone7,1"]) return @"iPhone 6 Plus";
- if ([deviceString isEqualToString:@"iPhone7,2"]) return @"iPhone 6";
- if ([deviceString isEqualToString:@"iPhone8,1"]) return @"iPhone 6s";
- if ([deviceString isEqualToString:@"iPhone8,2"]) return @"iPhone 6s Plus";
- //iPod
- if ([deviceString isEqualToString:@"iPod1,1"]) return @"iPod Touch 1G";
- if ([deviceString isEqualToString:@"iPod2,1"]) return @"iPod Touch 2G";
- if ([deviceString isEqualToString:@"iPod3,1"]) return @"iPod Touch 3G";
- if ([deviceString isEqualToString:@"iPod4,1"]) return @"iPod Touch 4G";
- if ([deviceString isEqualToString:@"iPod5,1"]) return @"iPod Touch 5G";
- return nil;
3.设备本地化类别:
4.获取设备的UUID:
5.获取当前手机运行的系统以及当前系统的版本
运行效果如下:
有时候我们也需要获取当前App的相关信息,比如当前应用名称, 当前版本号,用于判断是否应该提示用户升级App等.
代码如下:
以上是关于IOS -iphone设备信息读取的主要内容,如果未能解决你的问题,请参考以下文章