gpt4 book ai didi

ios - UIDevice currentDevice 模型可能的值

转载 作者:IT王子 更新时间:2023-10-29 05:12:48 28 4
gpt4 key购买 nike

[[UIDevice currentDevice] model]; 返回的所有可能值是什么?它不是 documented .

最佳答案

可能的值是iPod touchiPhoneiPhone SimulatoriPadiPad Simulator

如果你想知道哪个硬件 iOS 正在毁坏像 iPhone3, iPhone4, iPhone5 等下面是那个的代码


注意:下面的代码可能不包含所有设备的字符串,我和其他人在 GitHub 上维护相同的代码所以请从那里获取最新代码

objective-C :GitHub/DeviceUtil

swift :GitHub/DeviceGuru


#include <sys/types.h>
#include <sys/sysctl.h>

- (NSString*)hardwareDescription {
NSString *hardware = [self hardwareString];
if ([hardware isEqualToString:@"iPhone1,1"]) return @"iPhone 2G";
if ([hardware isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";
if ([hardware isEqualToString:@"iPhone3,1"]) return @"iPhone 4";
if ([hardware isEqualToString:@"iPhone4,1"]) return @"iPhone 4S";
if ([hardware isEqualToString:@"iPhone5,1"]) return @"iPhone 5";
if ([hardware isEqualToString:@"iPod1,1"]) return @"iPodTouch 1G";
if ([hardware isEqualToString:@"iPod2,1"]) return @"iPodTouch 2G";
if ([hardware isEqualToString:@"iPad1,1"]) return @"iPad";
if ([hardware isEqualToString:@"iPad2,6"]) return @"iPad Mini";
if ([hardware isEqualToString:@"iPad4,1"]) return @"iPad Air WIFI";
//there are lots of other strings too, checkout the github repo
//link is given at the top of this answer

if ([hardware isEqualToString:@"i386"]) return @"Simulator";
if ([hardware isEqualToString:@"x86_64"]) return @"Simulator";

return nil;
}

- (NSString*)hardwareString {
size_t size = 100;
char *hw_machine = malloc(size);
int name[] = {CTL_HW,HW_MACHINE};
sysctl(name, 2, hw_machine, &size, NULL, 0);
NSString *hardware = [NSString stringWithUTF8String:hw_machine];
free(hw_machine);
return hardware;
}

关于ios - UIDevice currentDevice 模型可能的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14411075/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com