I read in Xcode 2.x's documentation that the best way seems to get it out of the file /System/Library/CoreServices/SystemVersion.plist. Even though it is a plain-text XML file, I didn't just parse it via brute-force and get at the number. So I had to parse it properly. It turns out to be pretty easy.
NSString * text = [NSString stringWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"];
NSDictionary * plist = [text propertyListFromStringsFileFormat];
NSString * productVersion = [plist valueForKey:@"ProductVersion"];
NSDictionary * plist = [text propertyListFromStringsFileFormat];
NSString * productVersion = [plist valueForKey:@"ProductVersion"];
Three lines of code, and I can get at the strings such as 10.4.9 for Tiger and 10.5 for Leopard. Simple. I like it.
No comments:
Post a Comment