iOS——设备信息获取

这段代码用于获取iOS设备的型号(如iPhone4S、iPhone6Plus等)和APP及系统的版本信息。通过设备的utsname结构体获取设备型号,并根据预定义的型号字符串匹配返回友好的设备名称。同时,提供了获取APP的版本号和设备系统版本的方法。
摘要由CSDN通过智能技术生成

1.导入

#import

//MARK: 获取设备型号

+ (NSString *)currentPhoneModel {

    

    struct utsname systemInfo;

    uname(&systemInfo);

    NSString *phoneModel = [NSString stringWithCString: systemInfo.machine encoding:NSASCIIStringEncoding];

    if ([phoneModel isEqualToString:@"iPhone3,1"] ||

        [phoneModel isEqualToString:@"iPhone3,2"])   return @"iPhone 4";

    if ([phoneModel isEqualToString:@"iPhone4,1"])   return @"iPhone 4S";

    if ([phoneModel isEqualToString:@"iPhone5,1"] ||

        [phoneModel isEqualToString:@"iPhone5,2"])   return @"iPhone 5";

    if ([phoneModel isEqualToString:@"iPhone5,3"] ||

        [phoneModel isEqualToString:@"iPhone5,4"])   return @"iPhone 5C";

    if ([phoneModel isEqualToString:@"iPhone6,1"] ||

        [phoneModel isEqualToString:@"iPhone6,2"])   return @"iPhone 5S";

    if ([phoneModel isEqualToString:@"iPhone7,1"]) return @"iPhone 6 Plus";

    if ([phoneModel isEqualToString:@"iPhone7,2"]) return @"iPhone 6";

    if ([phoneModel isEqualToString:@"iPhone8,1"]) return @"iPhone 6s";

    if ([phoneModel isEqualToString:@"iPhone8,2"]) return @"iPhone 6s Plus";

    if ([phoneModel isEqualToString:@"iPhone8,4"]) return @"iPhone SE";

    if ([phoneModel isEqualToString:@"iPhone9,1"]) return @"iPhone 7";

    if ([phoneModel isEqualToString:@"iPhone9,2"]) return @"iPhone 7 Plus";

    if ([phoneModel isEqualToString:@"iPhone10,1"] ||

        [phoneModel isEqualToString:@"iPhone10,4"]) return @"iPhone 8";

    if ([phoneModel isEqualToString:@"iPhone10,2"] ||

        [phoneModel isEqualToString:@"iPhone10,5"]) return @"iPhone 8 Plus";

    if ([phoneModel isEqualToString:@"iPhone10,3"] ||

        [phoneModel isEqualToString:@"iPhone10,6"]) return @"iPhone X";

    if ([phoneModel isEqualToString:@"iPhone11,8"])   return @"iPhone XR";

    if ([phoneModel isEqualToString:@"iPhone11,2"])   return @"iPhone XS";

    if ([phoneModel isEqualToString:@"iPhone11,6"] ||

        [phoneModel isEqualToString:@"iPhone11,4"])   return @"iPhone XS Max";

    

    return @"Unknown";

}

2.

//获取APP当前版本号

[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];

3.

//获取设备系统版本

[[UIDevice currentDevice] systemVersion];

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值