本文主要是介绍iOS 获取手机型号4s 5s 6s,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
先导入头文件#import "sys/sysctl.h"
下面是方法 放在你的工具类就可以了
//获取手机的型号 iPhone 4s iPhone 5s iPhone6s 。。。。
+ (NSString*) doDevicePlatform
{size_t size;int nR = sysctlbyname("hw.machine", NULL, &size, NULL, 0);char *machine = (char *)malloc(size);nR = sysctlbyname("hw.machine", machine, &size, NULL, 0);NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];free(machine);if ([platform isEqualToString:@"iPhone3,1"]||[platform isEqualToString:@"iPhone3,2"]||[platform isEqualToString:@"iPhone3,3"]) {platform = @"iPhone 4";} else if ([platform isEqualToString:@"iPhone4,1"]) {platform = @"iPhone 4S";} else if ([platform isEqualToString:@"iPhone5,1"]||[platform isEqualToString:@"iPhone5,2"]) {platform = @"iPhone 5";}else if ([platform isEqualToString:@"iPhone5,3"]||[platform isEqualToString:@"iPhone5,4"]) {platform = @"iPhone 5C";}else if ([platform isEqualToString:@"iPhone6,2"]||[platform isEqualToString:@"iPhone6,1"]) {platform = @"iPhone 5S";}return platform;
}
这篇关于iOS 获取手机型号4s 5s 6s的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!