From f3ed1fafe3fa86b99abc86fc804b7f595f796a8e Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Sun, 29 Jun 2014 23:17:32 -0400 Subject: [PATCH] Use new operatingSystemVersion API when available. --- Sparkle/SUHost.m | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Sparkle/SUHost.m b/Sparkle/SUHost.m index 9dc50586..f628dc70 100644 --- a/Sparkle/SUHost.m +++ b/Sparkle/SUHost.m @@ -12,6 +12,17 @@ #include // For statfs for isRunningOnReadOnlyVolume #import "SULog.h" +#if __MAC_OS_X_VERSION_MAX_ALLOWED < 101000 +typedef struct { + NSInteger majorVersion; + NSInteger minorVersion; + NSInteger patchVersion; +} NSOperatingSystemVersion; +@interface NSProcessInfo () +- (NSOperatingSystemVersion)operatingSystemVersion; +@end +#endif + @interface SUHost () @property (retain, readwrite) NSBundle *bundle; @end @@ -246,8 +257,15 @@ + (NSString *)systemVersionString { - NSString *versionPlistPath = @"/System/Library/CoreServices/SystemVersion.plist"; - return [NSDictionary dictionaryWithContentsOfFile:versionPlistPath][@"ProductVersion"]; +#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1090 // Present in 10.9 despite NS_AVAILABLE's claims + if (![NSProcessInfo instancesRespondToSelector:@selector(operatingSystemVersion)]) + { + NSURL *coreServices = [[NSFileManager defaultManager] URLForDirectory:NSCoreServiceDirectory inDomain:NSSystemDomainMask appropriateForURL:nil create:NO error:nil]; + return [NSDictionary dictionaryWithContentsOfURL:[coreServices URLByAppendingPathComponent:@"SystemVersion.plist"]][@"ProductVersion"]; + } +#endif + NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion]; + return [NSString stringWithFormat:@"%ld.%ld.%ld", (long)version.majorVersion, (long)version.minorVersion, (long)version.patchVersion]; } @end