ios - UIDevice currentDevice 模型可能的值

标签 ios objective-c swift

[[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/

相关文章:

iphone - UIImagePicker 和覆盖

javascript - iOS UIAutomation 无法访问 TableView

objective-c - 如何自动推送

ios - UIStackView 中的第一个基线和最后一个基线属性

ios - 更改 @State 变量不会更新 SwiftUI 中的 View

ios - iOS 日历是否支持 URL 方案?

ios - 是否允许 iOS 应用程序中的动态语言更改?

ios - Xcode - 自定义 TableViewCell 显示错误数据

ios - 用音频单元录制音频,文件的每个文件都以X秒为单位分割

ios - 具有自动调整单元格的 Collection View 不再水平滚动