Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Mac Model number in Cocoa

I'm making a OS X app where I need to get the Mac model, for example:

iMac11,3
MacBook3,1

And so on. Is there any class, or function to get it?

like image 917
pmerino Avatar asked Sep 11 '11 10:09

pmerino


2 Answers

This information is available via. sysctl:

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

size_t len = 0;
sysctlbyname("hw.model", NULL, &len, NULL, 0);
if (len) {
    char *model = malloc(len*sizeof(char));
    sysctlbyname("hw.model", model, &len, NULL, 0);
    printf("%s\n", model);
    free(model);
}
like image 146
一二三 Avatar answered Nov 11 '22 02:11

一二三


The API for that would be in the IOKit. Looking in the IORegistryExplorer app on my laptop, I see that the first node from the root of the IOService tree is an IOPlatformExpertDevice, with a entry under the key "model" equal to "MacBookPro6,1"

like image 38
NSResponder Avatar answered Nov 11 '22 03:11

NSResponder