Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MacCatalyst] OperatingSystem is currently not working #21390

Closed
PureWeen opened this issue Oct 8, 2024 · 2 comments
Closed

[MacCatalyst] OperatingSystem is currently not working #21390

PureWeen opened this issue Oct 8, 2024 · 2 comments

Comments

@PureWeen
Copy link

PureWeen commented Oct 8, 2024

Description

It looks like on MacCatalyst the Build on the Environment.OSVersion.Version is set to "-1" so when you call

if (OperatingSystem.IsMacCatalystVersionAtLeast(18,0))

it resolves to false.
This works fine on iOS just not MacCatalyst

Reproduction

aoperatingsystem.zip

Just run the app and I've set a label on the screen to output the value of OSVersion.Version. I've also included some if statements in the main page you can break point

Catalyst

image

iOS

image

@drasticactions
Copy link
Member

drasticactions commented Oct 9, 2024

TL;DR macOS reports 18.0, SDK parses it as a Version which is where the -1 comes from, Runtime check will always report it as below.

https://github.com/drasticactions/MauiRepoRedux/tree/MacCatalystVersion

https://github.com/dotnet/runtime/blob/abde3f9498f09b5016a7a0d7d2e1b81ce5c1b614/src/libraries/System.Private.CoreLib/src/System/OperatingSystem.cs#L227

スクリーンショット 2024-10-09 14 19 32

https://github.com/dotnet/runtime/blob/abde3f9498f09b5016a7a0d7d2e1b81ce5c1b614/src/libraries/Common/src/Interop/OSX/System.Native/Interop.iOSSupportVersion.cs#L11

https://github.com/dotnet/runtime/blob/abde3f9498f09b5016a7a0d7d2e1b81ce5c1b614/src/libraries/System.Private.CoreLib/src/System/OperatingSystem.cs#L328-L341

#if __MACCATALYST__
static string? _iOSSupportVersion;
internal static string iOSSupportVersion {
get {
if (_iOSSupportVersion is null) {
// This is how Apple does it: https://github.com/llvm/llvm-project/blob/62ec4ac90738a5f2d209ed28c822223e58aaaeb7/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm#L100-L105
using var dict = NSMutableDictionary.FromFile ("/System/Library/CoreServices/SystemVersion.plist");
using var str = (NSString) "iOSSupportVersion";
using var obj = dict.ObjectForKey (str);
_iOSSupportVersion = obj.ToString ();
}
return _iOSSupportVersion;
}
}
#endif

image

platformInfo.Version = Version.Parse (version);

That value is coming from SystemVersion.plist, which is 18.0, hence why it would get -1, since it's Version.Parseed and it doesn't have the Build number that it may have had in the past.

https://github.com/dotnet/runtime/blob/abde3f9498f09b5016a7a0d7d2e1b81ce5c1b614/src/libraries/System.Private.CoreLib/src/System/OperatingSystem.cs#L344

It may be that this needed that the -1 check needs to also be added to build for the same reason as revision, since it can't be assumed that build will be there. Or the SDK code above that fetches the version should always include the build even if the system doesn't provide it.

To work around it, checking against18 0 -1 should work

@rolfbjarne
Copy link
Member

This issue was moved to dotnet/runtime#108694

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants