I'm looking for some short code to just catch the type of mac (in descriptive string format) that my Obj-C app is running on.
Like: 'MacBook Pro (Retina, 15-inch, Late 2013)'
thanks
It's not too bad, but you will have to use a bit of C. This answer is taken from an excellent blog post about the subject at http://joris.kluivers.nl/blog/2013/11/28/model-identifiers/. The gist of it is that you use sysctlbyname() to find the model identifier like MacBookPro8,2, then translate it to a human readable string. This snippet creates the model identifier:
#include <sys/types.h>
#include <sys/sysctl.h>
size_t size;
sysctlbyname("hw.model", NULL, &size, NULL, 0);
char *model = malloc(size);
sysctlbyname("hw.model", model, &size, NULL, 0);
NSLog(@"%s", model); // You would probably copy it to a NSString for later use
free(model);
Once you have that string as an NSString, there's unfortunately not a built in way to convert between the identifier and a nicely displayed name. But I found this site http://www.everymac.com/systems/by_capability/mac-specs-by-machine-model-machine-id.html, that seems to have all mac models you could possibly want, updated, with a simple translation between the name and the identifier. You'd have to do a bit of work to put that into a file, but shouldn't be too bad. Hope that helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With