 |
 |
How to detect system information
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Oct 2006
Status:
Offline
|
|
Hello,
Using Cocoa, how can you detect system information?
I would like to be able to determine which version of Mac OS is running and what the cpu type is.
Thank you for your help. (If this has been asked before, I'm very sorry. I did search the forums for a significant amount of time before deciding to post.)
Cheers,
Blam
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Aug 2001
Status:
Offline
|
|
SparklePlus has some code to do exactly this, and it's MIT-licensed so you can use it in anything.
The svn repository for it is at Revision 59: /trunk
<edit> I loathe how macnn retitles my links now </edit>
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
You can turn off the auto-link-name thing in the advanced post dialogue.
|
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Oct 2006
Status:
Offline
|
|
Thank you, Catfish.
Unfortunately, I don't understand what I'm supposed to do at the link you provided. When I click on it, it takes me to a page with links to code. I followed some of those links and was unable to find anything that would help me.
Can you be more specific about where the code I need is? In fact, I'd prefer if you (or someone) could direct me to an appkit class or something like that. The project I'm working on is just to help me get used to programming in Cocoa, so I'd prefer to do most of the coding myself.
If you can't help me, I understand. I don't expect anyone to go out of their way for me.
Thanks again for the link!
~Blam
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Oct 2006
Status:
Offline
|
|
P.S. I should mention that I have figured out how to detect the OS version. I'm still working on determing the CPU type (Intel or PPC). Here is my code for finding the version. There is probably a better way, but this works for me.
Code:
NSString *osVersion = [[NSString alloc]init];
float appkitNum = floor(NSAppKitVersionNumber);
if (appkitNum == 743.14) osVersion = @"10.3.2";
else if (appkitNum == 743.2) osVersion = @"10.3.3";
else if (appkitNum == 743.24) osVersion = @"10.3.5";
else if (appkitNum == 577) osVersion = @"10.0";
else if (appkitNum == 620) osVersion = @"10.1";
else if (appkitNum == 663) osVersion = @"10.2";
else if (appkitNum == 663.6) osVersion = @"10.2.3";
else if (appkitNum == 743) osVersion = @"10.3";
else if (appkitNum == 824) osVersion = @"10.4";
else osVersion = @"unknown operating system";
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
There isn't a method in AppKit to detect the processor, as far as I know. Check out this page on CocoaDev for an example of how it's done.
|
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Oct 2006
Status:
Offline
|
|
Thank you very much, Chuckit.
Your link was exactly what I needed. Below is what I ended up doing (in case anyone else is looking to do the same thing). The case values are taken from Chuck's link, so I don't know if they are free to use. (My project is just for my personal learning experience.)
Code:
NSString *cpuInfo = [[NSString alloc]init];
OSType cpuType;
long gestaltReturnValue;
cpuType = Gestalt(gestaltNativeCPUtype, &gestaltReturnValue);
switch(gestaltReturnValue) {
case gestaltCPU601: cpuInfo = @"PowerPC 601"; break;
case gestaltCPU603: cpuInfo = @"PowerPC 603"; break;
case gestaltCPU603e: cpuInfo = @"PowerPC 603e"; break;
case gestaltCPU603ev: cpuInfo = @"PowerPC 603ev"; break;
case gestaltCPU604: cpuInfo = @"PowerPC 604"; break;
case gestaltCPU604e: cpuInfo = @"PowerPC 604e"; break;
case gestaltCPU604ev: cpuInfo = @"PowerPC 604ev"; break;
case gestaltCPU750: cpuInfo = @"G3"; break;
case gestaltCPUG4: cpuInfo = @"G4"; break;
case gestaltCPU970: cpuInfo = @"G5 (970)"; break;
case gestaltCPU970FX: cpuInfo = @"G5 (970 FX)"; break;
case gestaltCPU486 : cpuInfo = @"Intel 486"; break;
case gestaltCPUPentium: cpuInfo = @"Intel Pentium"; break;
case gestaltCPUPentiumPro: cpuInfo = @"Intel Pentium Pro"; break;
case gestaltCPUPentiumII: cpuInfo = @"Intel Pentium II"; break;
case gestaltCPUX86: cpuInfo = @"Intel x86"; break;
case gestaltCPUPentium4: cpuInfo = @"Intel Pentium 4"; break;
default: NSLog(@"error calling Gestalt: %d", cpuType);
}
I then used the NSString defined in the switch statement in an alert panel.
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jan 2002
Location: Melbourne, Australia
Status:
Offline
|
|
You can also get the info from The IORegistry. I suspect it might be a bit more accurate since technically none of the released Intel Macs use the Intel CPUs you have listed there. See: IODeviceTree/Root/device-tree/cpus
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Apr 2004
Status:
Offline
|
|
I think you've maybe got a memory leak there. you shouldn't need to alloc or init your string, since you're assigning it to a constant value anyway, right? so then you'll have an extra NSString alloced that never gets released.
shrug.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|