In this article: Detecting the Operating System in .NET Core, describe to check the Operating System, but only Windows, macOS and Linux. Is posible to check a mobile Operating System (Android/iOS/iPadiOS) in NET Core or Net Standard 2.0?.
Asked
Active
Viewed 344 times
1
-
Are you using Xamarin or Maui? – Kirk Woll Jun 28 '22 at 17:31
-
.NET Standard 2.0 library, which is shared in others projects: Xamarin Forms App and WPF NET Framework. – Ejrr1085 Jun 28 '22 at 17:41
-
I suspect there's no standard solution for this. (Would be happy to be proven wrong) But in your shoes, I'd probably create an interface (like `IGetPlatform` or something) with a method (like `GetPlatform()`) wherein for Xamarin, you inject an implementation that uses [this answer](https://stackoverflow.com/questions/18570878/how-to-know-the-current-os-platform-of-the-executing-code-android-ios) and for others, inject an implementation that uses the link you provided. – Kirk Woll Jun 28 '22 at 19:40
-
The interface would live in your .NET Standard library, and the implementations (or at least the Xamarin one) would live in their respective projects. – Kirk Woll Jun 28 '22 at 19:42
-
I thought of something similar, every time the net standard 2.0 library is used, some property must be initialized with the respective operating system that invokes this dll, maybe with Device.RuntimePlatform from Xamarin.Forms referenced in net standard 2.0 library. – Ejrr1085 Jun 28 '22 at 21:29
-
I was testing and with Android, System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux) returns true, I guess with iOS or iPadiOS System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime. InteropServices.OSPlatform.OSX) returns true. – Ejrr1085 Jun 28 '22 at 21:30