年年有"余"

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 3811|回复: 2

如何判断当前iPhone的机型,iPhone代号对应关系

[复制链接]
  • TA的每日心情

    2024-10-15 10:05
  • 签到天数: 372 天

    [LV.9]以坛为家II

    发表于 2015-4-7 16:18:12 | 显示全部楼层 |阅读模式
    不多说,直接上代码,拿去用即可!!别问我是怎么知道,如果你有这么多手机的话你也可以去测。
    [Objective-C] 纯文本查看 复制代码
    + (NSString *)deviceString
    {
        struct utsname systemInfo;
        uname(&systemInfo);
        NSString *deviceString = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
        
        if ([deviceString isEqualToString:@"iPhone1,1"])    return @"iPhone 1G";
        if ([deviceString isEqualToString:@"iPhone1,2"])    return @"iPhone 3G";
        if ([deviceString isEqualToString:@"iPhone2,1"])    return @"iPhone 3GS";
        if ([deviceString isEqualToString:@"iPhone3,1"])    return @"iPhone 4";
        if ([deviceString isEqualToString:@"iPhone3,2"])    return @"iPhone 4";
        if ([deviceString isEqualToString:@"iPhone3,3"])    return @"iPhone 4";
        if ([deviceString isEqualToString:@"iPhone4,1"])    return @"iPhone 4S";
        if ([deviceString isEqualToString:@"iPhone5,1"])    return @"iPhone 5";
        if ([deviceString isEqualToString:@"iPhone5,2"])    return @"iPhone 5";
        if ([deviceString isEqualToString:@"iPhone5,3"])    return @"iPhone 5C";
        if ([deviceString isEqualToString:@"iPhone5,4"])    return @"iPhone 5C";
        if ([deviceString isEqualToString:@"iPhone6,1"])    return @"iPhone 5S";
        if ([deviceString isEqualToString:@"iPhone6,2"])    return @"iPhone 5S";
        if ([deviceString isEqualToString:@"iPhone7,2"])    return @"iPhone 6";
        if ([deviceString isEqualToString:@"iPhone7,1"])    return @"iPhone 6 Plus";
        if ([deviceString isEqualToString:@"i386"])         return @"Simulator";
        if ([deviceString isEqualToString:@"x86_64"])       return @"Simulator";
        else return @"Unknown Device";
        return deviceString;
    }


  • TA的每日心情
    恶心
    2015-11-23 14:20
  • 签到天数: 92 天

    [LV.6]常住居民II

    发表于 2015-6-4 09:17:30 | 显示全部楼层
    本帖最后由 喵了个咪 于 2015-6-4 09:20 编辑

    还要导入头文件 #import "sys/utsname.h" , 不然会找不到 utsname systemInfo
  • TA的每日心情

    2024-10-15 10:05
  • 签到天数: 372 天

    [LV.9]以坛为家II

     楼主| 发表于 2015-6-5 12:13:32 | 显示全部楼层
    喵了个咪 发表于 2015-6-4 09:17
    还要导入头文件 #import "sys/utsname.h" , 不然会找不到 utsname systemInfo

    楼上正解!
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    手机版|小黑屋|Archiver|iOS开发笔记 ( 湘ICP备14010846号 )

    GMT+8, 2024-12-5 03:17 , Processed in 0.046251 second(s), 22 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表