UIDevice currentDevice模型可能的值 [英] UIDevice currentDevice model possible values

查看:575
本文介绍了UIDevice currentDevice模型可能的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

推荐答案

可能的价格是 iPod touch iPhone iPhone模拟器 iPad iPad模拟器

The possible vales are iPod touch, iPhone, iPhone Simulator, iPad, iPad Simulator

如果你想知道哪个硬件 iOS 正在破坏像 iPhone3 iPhone4 iPhone5 等以下是该代码

If you want to know which hardware iOS is ruining on like iPhone3, iPhone4, iPhone5 etc below is the code for that

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

NOTE: The below code may not contain all device's string, I'm with other guys are maintaining the same code on GitHub so please take the latest code from there

Objective-C:GitHub/DeviceUtil

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;
}

这篇关于UIDevice currentDevice模型可能的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆