OS X version checking in Cocoa

前端 未结 5 640
猫巷女王i
猫巷女王i 2020-12-10 19:11

I am developing a Cocoa application and need to check whether the current OS X version is OS X 10.6 Snow Leopard

If the current version is Snow Leopard, I need to cl

5条回答
  •  借酒劲吻你
    2020-12-10 19:20

    There are a couple ways you could do this.

    1. You could check for the existence of a 10.6 only class:

      Class snowLeopardOnlyClass = NSClassFromString(@"NSRunningApplication");
      if (snowLeopardOnlyClass != nil) {
        NSLog(@"I'm running on Snow Leopard!");
      }
    2. Use a system function (like Gestalt) to determine the OS version:

      #import 
      SInt32 major = 0;
      SInt32 minor = 0;   
      Gestalt(gestaltSystemVersionMajor, &major);
      Gestalt(gestaltSystemVersionMinor, &minor);
      if ((major == 10 && minor >= 6) || major >= 11) {
        NSLog(@"I'm running on Snow Leopard (at least!)");
      }

提交回复
热议问题