macOS 開(kāi)發(fā)獲取機(jī)型

只獲取了2017后的機(jī)型

- (NSString *)getDeviceModel {
    NSString *result = @"";
    size_t size = 0;
    sysctlbyname("hw.model", NULL, &size, NULL, 0);
    if (size != 0) {
        char machine[size];
        sysctlbyname("hw.model", machine, &size, NULL, 0);
        result = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
    }

    return macDeviceModel(result);
}


- (NSString *)macDeviceModel:(NSString *)model {
    NSString *deviceModel = model;
    
    if ([deviceModel isEqualToString:@"Macmini9,1"]) {
        return @"Mac mini (M1, 2020)";
    } else if ([deviceModel isEqualToString:@"iMac21,1"] || [deviceModel isEqualToString:@"iMac21,2"]) {
        return @"iMac (24-inch, M1, 2021)";
    }
    else if ([deviceModel isEqualToString:@"Mac13,1"] || [deviceModel isEqualToString:@"Mac13,2"]) {
        return @"Mac Studio";
    }
    else if ([deviceModel isEqualToString:@"Mac14,3"] || [deviceModel isEqualToString:@"Mac14,12"]) {
        return @"Mac mini (2023)";
    }
    else if ([deviceModel isEqualToString:@"Mac14,8"]) {
        return @"Mac Pro (2023)";
    }
    else if ([deviceModel isEqualToString:@"Mac14,13"] || [deviceModel isEqualToString:@"Mac14,14"]) {
        return @"Mac Studio (2023)";
    }
    else if ([deviceModel isEqualToString:@"Mac15,4"] || [deviceModel isEqualToString:@"Mac15,5"]) {
        return @"iMac (24-inch, 2023)";
    }
    else if ([deviceModel isEqualToString:@"MacBookAir10,1"]) {
        return @"MacBook Air (M1, 2020)";
    }
    else if ([deviceModel isEqualToString:@"MacBookPro17,1"]) {
        return @"MacBook Pro (13-inch, M1, 2020)";
    }
    else if ([deviceModel isEqualToString:@"MacBookPro18,3"] || [deviceModel isEqualToString:@"MacBookPro18,4"]) {
        return @"MacBook Pro (14-inch, 2021)";
    }
    else if ([deviceModel isEqualToString:@"MacBookPro18,1"] || [deviceModel isEqualToString:@"MacBookPro18,2"]) {
        return @"MacBook Pro (16-inch, 2021)";
    }
    else if ([deviceModel isEqualToString:@"Mac14,2"]) {
        return @"MacBook Air (M2, 2022)";
    }
    else if ([deviceModel isEqualToString:@"Mac14,7"]) {
        return @"MacBook Pro (13-inch, M2, 2022)";
    }
    else if ([deviceModel isEqualToString:@"Mac14,5"] || [deviceModel isEqualToString:@"Mac14,9"]) {
        return @"MacBook Pro (14-inch, 2023)";
    }
    else if ([deviceModel isEqualToString:@"Mac14,6"] || [deviceModel isEqualToString:@"Mac14,10"]) {
        return @"MacBook Pro (16-inch, 2023)";
    }
    else if ([deviceModel isEqualToString:@"Mac14,8"]) {
        return @"MacBook Air (15-inch, M2, 2023)";
    }
    else if ([deviceModel isEqualToString:@"Mac15,3"] || [deviceModel isEqualToString:@"Mac15,6"] || [deviceModel isEqualToString:@"Mac15,8"] || [deviceModel isEqualToString:@"Mac15,10"]) {
        return @"MacBook Pro (14-inch, Nov 2023)";
    }
    else if ([deviceModel isEqualToString:@"Mac15,7"] || [deviceModel isEqualToString:@"Mac15,9"] || [deviceModel isEqualToString:@"Mac15,11"]) {
        return @"MacBook Pro (16-inch, Nov 2023)";
    }
    else if ([deviceModel isEqualToString:@"Mac15,12"]) {
        return @"MacBook Air (13-inch, M3, 2024)";
    }
    else if ([deviceModel isEqualToString:@"Mac15,13"]) {
        return @"MacBook Air (15-inch, M3, 2024)";
    }
    else if ([deviceModel isEqualToString:@"iMac18,1"]) {
        return @"iMac (Retina 4K, 21.5-inch, 2017)";
    }
    else if ([deviceModel isEqualToString:@"iMac18,2"]) {
        return @"iMac (Retina 4K, 21.5-inch, 2017)";
    }
    else if ([deviceModel isEqualToString:@"iMac18,3"]) {
        return @"iMac (Retina 5K, 27-inch, 2017)";
    }
    else if ([deviceModel isEqualToString:@"iMacPro1,1"]) {
        return @"iMac Pro (2017)";
    }
    else if ([deviceModel isEqualToString:@"iMac19,1"]) {
        return @"iMac (Retina 5K, 27-inch, 2019)";
    }
    else if ([deviceModel isEqualToString:@"iMac19,2"]) {
        return @"iMac (Retina 4K, 21.5-inch, 2019)";
    }
    else if ([deviceModel isEqualToString:@"iMac20,1"] || [deviceModel isEqualToString:@"iMac20,2"]) {
        return @"iMac (Retina 5K, 27-inch, 2020)";
    }
    else if ([deviceModel isEqualToString:@"MacBookPro14,1"] || [deviceModel isEqualToString:@"MacBookPro14,2"] || [deviceModel isEqualToString:@"MacBookPro14,3"]) {
        return @"MacBook Pro 2017";
    }
    else if ([deviceModel isEqualToString:@"MacBookPro15,1"] || [deviceModel isEqualToString:@"MacBookPro15,2"] || [deviceModel isEqualToString:@"MacBookPro15,3"]) {
        return @"MacBook Pro 2018";
    }
    else if ([deviceModel isEqualToString:@"MacBookPro15,4"]) {
        return @"MacBook Pro 2019 (Butterfly Keyboard)";
    }
    else if ([deviceModel isEqualToString:@"MacBookPro16,1"] || [deviceModel isEqualToString:@"MacBookPro16,4"]) {
        return @"MacBook Pro 2019 (Magic Keyboard)";
    }
    else if ([deviceModel isEqualToString:@"MacBookPro16,2"] || [deviceModel isEqualToString:@"MacBookPro16,3"]) {
        return @"MacBook Pro 2020";
    }
    else if ([deviceModel isEqualToString:@"MacBookAir7,2"]) {
        return @"MacBook Air 2017";
    }
    else if ([deviceModel isEqualToString:@"MacBookAir8,1"]) {
        return @"MacBook Air 2018";
    }
    else if ([deviceModel isEqualToString:@"MacBookAir8,2"]) {
        return @"MacBook Air 2019";
    }
    else if ([deviceModel isEqualToString:@"MacBookAir9,1"]) {
        return @"MacBook Air 2020";
    }
    else if ([deviceModel isEqualToString:@"Macmini7,1"]) {
        return @"Mac mini (Late 2014)";
    }
    else if ([deviceModel isEqualToString:@"Macmini8,1"]) {
        return @"Mac mini 2018";
    }
    else if ([deviceModel isEqualToString:@"MacPro7,1"]) {
        return @"Mac Pro 2019";
    }
    return @"Mac";
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末趋急,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子谣蠢,更是在濱河造成了極大的恐慌查近,老刑警劉巖,帶你破解...
    沈念sama閱讀 211,265評(píng)論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件勋锤,死亡現(xiàn)場(chǎng)離奇詭異侥祭,居然都是意外死亡茄厘,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,078評(píng)論 2 385
  • 文/潘曉璐 我一進(jìn)店門胎署,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)窑滞,“玉大人,你說(shuō)我怎么就攤上這事巨坊〈烁模” “怎么了?”我有些...
    開(kāi)封第一講書人閱讀 156,852評(píng)論 0 347
  • 文/不壞的土叔 我叫張陵占调,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我究珊,道長(zhǎng),這世上最難降的妖魔是什么剿涮? 我笑而不...
    開(kāi)封第一講書人閱讀 56,408評(píng)論 1 283
  • 正文 為了忘掉前任,我火速辦了婚禮纺念,結(jié)果婚禮上想括,老公的妹妹穿的比我還像新娘。我一直安慰自己瑟蜈,他們只是感情好蔗衡,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,445評(píng)論 5 384
  • 文/花漫 我一把揭開(kāi)白布贺嫂。 她就那樣靜靜地躺著雏胃,像睡著了一般掂林。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上泻帮,一...
    開(kāi)封第一講書人閱讀 49,772評(píng)論 1 290
  • 那天,我揣著相機(jī)與錄音脂倦,去河邊找鬼元莫。 笑死,一個(gè)胖子當(dāng)著我的面吹牛政供,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播布隔,決...
    沈念sama閱讀 38,921評(píng)論 3 406
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼衅檀,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了沉眶?” 一聲冷哼從身側(cè)響起杉适,我...
    開(kāi)封第一講書人閱讀 37,688評(píng)論 0 266
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎片习,沒(méi)想到半個(gè)月后蹬叭,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,130評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡孽查,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,467評(píng)論 2 325
  • 正文 我和宋清朗相戀三年盲再,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了起宽。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片济榨。...
    茶點(diǎn)故事閱讀 38,617評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖腐晾,靈堂內(nèi)的尸體忽然破棺而出丐一,到底是詐尸還是另有隱情,我是刑警寧澤巨柒,帶...
    沈念sama閱讀 34,276評(píng)論 4 329
  • 正文 年R本政府宣布,位于F島的核電站晶乔,受9級(jí)特大地震影響牺勾,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜翻具,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,882評(píng)論 3 312
  • 文/蒙蒙 一回还、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧晾虑,春花似錦、人聲如沸帜篇。這莊子的主人今日做“春日...
    開(kāi)封第一講書人閱讀 30,740評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)竟痰。三九已至掏呼,卻和暖如春坏快,著一層夾襖步出監(jiān)牢的瞬間莽鸿,已是汗流浹背拾给。 一陣腳步聲響...
    開(kāi)封第一講書人閱讀 31,967評(píng)論 1 265
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留蒋得,地道東北人级及。 一個(gè)月前我還...
    沈念sama閱讀 46,315評(píng)論 2 360
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像额衙,于是被迫代替她去往敵國(guó)和親饮焦。 傳聞我的和親對(duì)象是個(gè)殘疾皇子怕吴,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,486評(píng)論 2 348

推薦閱讀更多精彩內(nèi)容