Getting MacOS Version in iOS Apps running on Apple Silicon Mac

I want to get MacOS Version from Objective-C build for iOS Apps to run on Apple Silicon Mac.

Because AppStore In-App Purchase on Apple Silicon Mac had issues on MacOS version 13.0 and was fixed at version 13.3.1.

I need to know the exact version of the MacOS to prevent users from buying In-App Purchases.

I found that I can get iOS version that the app is emulating on and assume MacOS version from iOS version. But I think it's not 100% guaranteed way, because no documentation says anything about it.

Is there a way to get MacOS Version in iOS Apps running on Apple Silicon Mac?

Answered by DTS Engineer in 798896022

I’m not sure if this is the best way to do this, but one way is to use uname:

func darwinVersion() -> String? {
    var uts = utsname()
    let ok = uname(&uts) >= 0
    guard ok else { return nil }
    return withUnsafePointer(to: &uts) { utsPtr in
        String(cString: utsPtr.pointer(to: \.release.0)!)
    }
}

This returns the Darwin version. For example, on macOS 14.5 that’s 23.5.0.

Now, the Darwin versions of iOS and macOS overlap, so you’ll want to conditionalise this code so that you only run it on macOS.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I’m not sure if this is the best way to do this, but one way is to use uname:

func darwinVersion() -> String? {
    var uts = utsname()
    let ok = uname(&uts) >= 0
    guard ok else { return nil }
    return withUnsafePointer(to: &uts) { utsPtr in
        String(cString: utsPtr.pointer(to: \.release.0)!)
    }
}

This returns the Darwin version. For example, on macOS 14.5 that’s 23.5.0.

Now, the Darwin versions of iOS and macOS overlap, so you’ll want to conditionalise this code so that you only run it on macOS.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Getting MacOS Version in iOS Apps running on Apple Silicon Mac
 
 
Q