On iOS, there is a UIDevice class which lets you get tons of great info about the device model, operating system etc…
I am looking for something equivalent on the Mac. I know about calling system_profiler
from the command line, but even the mini
setting takes several seconds to get any info.
I am interested in fast ways to get the machine type (Macbook Air, Mac Mini, etc…), OS version, and other quick machine details from within a Mac App. The details are going o be used as a footer on support emails sent from within the app. Is there any equivalent to UIDevice, or another fast way to get some info that could help describe a user's machine?
Etymology 1. From Spanish cacao, from Classical Nahuatl cacahuatl. The form cocoa by confusion with coco, popularized by Samuel Johnson's A Dictionary of the English Language. Doublet of cacao.
Cocoa is a set of object-oriented frameworks that provides a runtime environment for applications running in OS X and iOS. Cocoa is the preeminent application environment for OS X and the only application environment for iOS.
Cocoa, which includes the Foundation and AppKit frameworks, is used for developing applications that run on OS X. Cocoa Touch, which includes Foundation and UIKit frameworks, is used for developing applications that run on iOS.
The first thing your interface needs is a way for the user to enter the two numbers to multiply. A basic textbox is appropriate for this purpose. Click on the "Cocoa-Text" tab of the interface elements palette. From this tab you should drag a basic text box onto the applications window.
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/sysctl.h>
+ (NSString *)machineModel
{
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);
NSString *model_ns = [NSString stringWithUTF8String:model];
free(model);
return model_ns;
}
return @"Just an Apple Computer"; //in case model name can't be read
}
Swift version (just swap hw.model
for hw.machine
) is here https://stackoverflow.com/a/25467259/308315
Does calling system_profiler SPHardwareDataType
give you what you need? It returns very quickly and returns some basic hardware info. You can find out what other data you can request by calling system_profiler -listDataTypes
. I think the other piece to your puzzle will be system_profiler SPSoftwareDataType
.
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