// 简单获取类型 NSLog(@"name = %@", [[UIDevice currentDevice] name]); NSLog(@"model = %@", [[UIDevice currentDevice] model]); // 这里就可以简单判断是否iPhone、iPad、iPod NSLog(@"localizedModel = %@", [[UIDevice currentDevice] localizedModel]); NSLog(@"systemName = %@", [[UIDevice currentDevice] systemName]); NSLog(@"systemVersion = %@", [[UIDevice currentDevice] systemVersion]); // 调用私有函数获取设备名称 static CFStringRef (*$MGCopyAnswer)(CFStringRef); void *gestalt = dlopen("/usr/lib/libMobileGestalt.dylib", RTLD_GLOBAL | RTLD_LAZY); $MGCopyAnswer = (dlsym(gestalt, "MGCopyAnswer")); NSLog(@"DeviceName = %@", (__bridge NSString *)$MGCopyAnswer(CFSTR("DeviceName")); // 方法1: struct utsname systeminfo; uname(&systeminfo); NSString *sysname = [NSString stringWithCString:systeminfo.sysname encoding:NSUTF8StringEncoding]; NSLog(@"[++++]sysname = %@", sysname); NSString *hardware = [NSString stringWithCString:systeminfo.machine encoding:NSUTF8StringEncoding]; NSLog(@"[++++]platform = %@", hardware); NSString *nodename = [NSString stringWithCString:systeminfo.nodename encoding:NSUTF8StringEncoding]; NSLog(@"[++++]nodename = %@", nodename); NSString *release = [NSString stringWithCString:systeminfo.release encoding:NSUTF8StringEncoding]; NSLog(@"[++++]release = %@", release); NSString *version = [NSString stringWithCString:systeminfo.version encoding:NSUTF8StringEncoding]; NSLog(@"[++++]version = %@", version); NSLog(@"[++++]hardwareDisplayName = %@", [self hardwareDisplayName:hardware]); // 方法2: size_t size = 100; char *hw_machine = malloc(size); int name[] = {CTL_HW, HW_MACHINE}; sysctl(name, 2, hw_machine, &size, NULL, 0); hardware = [NSString stringWithUTF8String:hw_machine]; free(hw_machine); NSLog(@"[++++]hardware = %@", hardware); NSLog(@"[++++]hardwareDisplayName = %@", [self hardwareDisplayName:hardware]);
对照函数
hardwareDisplayName
见:https://www.dllhook.com/post/77.html
发表评论