Search code examples
macosappstore-approvalmac-app-storeappstore-sandbox

In a macOS application targeted for the Mac App Store, is the use of sysctlbyname allowed to get the current Mac model?


I am using this Objective-C code in my macOS apps:

#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"; //incase model name can't be read
}

For the moment, none of my apps have been rejected for this reason. Is it possible that this code can bring me to submission problems in the future ?

Many thanks for your help.


Solution

  • For the moment, none of my apps have been rejected for this reason. Is it possible that this code can bring me to submission problems in the future ?

    You are correct that sysctlbyname is currently, to the best of our knowledge, freely usable by MAS apps for getting information – there are other apps in the store which use it.

    Will Apple ever change the rules? Who knows, not even Apple probably.

    However if some software starts using the information gleaned for nefarious purposes then expect the use of this function to be curtailed. Hackers, down through advertisers, all the way down to politicians are the reason we often can't have nice things ;-(