How to know what Mac OS the app is running on?

后端 未结 7 1958
遥遥无期
遥遥无期 2020-12-31 18:30

I\'ve seen in some projects something like:

#if .....
    code...
#endif

but i can\'t find it now...
Let\'s say, for example, if the ap

7条回答
  •  有刺的猬
    2020-12-31 19:12

    You can get OS version like this:

    NSString *version = [[NSProcessInfo processInfo] operatingSystemVersionString];
    
    NSLog(version);
    

    Output:

    screenshot


    And I see You want to get just version. It can be done like this:

    NSString *version = [[NSProcessInfo processInfo] operatingSystemVersionString];
    
    NSRange range = NSMakeRange(8, 4);
    NSString *justVersion = [version substringWithRange: range];
    
    NSLog(@"%@", justVersion);
    

    Result:

    screenshot

    And for checking:

    if ([justVersion isEqualToString:@"10.7"]) {
        code...
    }
    else {
        ...
    }
    

提交回复
热议问题