I need to get it as a string to use elsewhere in the program, I'm not worried about compiler settings.
开发者_开发百科I found HowToGetHardwareAndNetworkInfo on CocoaDev, but it seemed a little intense when all I wanted to know is PPC vs. Intel.
If your application is built fat (i.e. isn't running under rosetta on intel), you don't need to make any calls to get this information, because different code will be running, depending on which architecture you're on. Thus, the information is available at compile time:
#if defined __i386__ || defined __x86_64__
NSString *processorType = @"Intel";
#elif defined __ppc__ || defined __ppc64__
NSString *processorType = @"PPC";
#elif defined __arm__
NSString *processorType = @"ARM";
#else
NSString *processorType = @"Unknown Architecture";
#endif
If you really want to do the determination at runtime for some perverse reason, you should be able to use the sysctlbyname
function, defined in <sys/sysctl.h>
.
How about uname
?
struct utsname uts;
uname(&uts);
printf("%s\n", uts.machine);
Will print like PPC or i386 or x86_64 depending on the machine.
The only part of that mess which you actually care about is here:
host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
See the Mach headers in Kernel.framework for struct and constant definitions.
精彩评论