如何知道执行代码的当前操作系统/平台(Android/iOS) [英] How to know the current OS / platform of the executing code (Android / iOS)

查看:23
本文介绍了如何知道执行代码的当前操作系统/平台(Android/iOS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Xamarin.Android 和 Xamarin.iOS,我现在需要共享代码部分中的当前操作系统.无论是枚举、整数还是字符串,都没有关系.

Using Xamarin.Android and Xamarin.iOS, I need to now the current OS in a shared code section. Be it an enum, an int or a string, it doesn't matter.

我试过了:

System.Environment.OSVersion

总是带有一些内核版本信息的Unix".

Which is always "Unix" with some kernel version informations.

Android 上有一些信息,例如

There are info on Android for example like

Android.OS.Build.VERSION

但它需要在 Android 特定的代码部分.有什么办法可以知道公共库中当前的操作系统吗?

But it needs to be in the Android specific code section. Is there any way of knowing the current OS in a common library?

推荐答案

你也可以试试这个,它可能是我找到的最好的解决方案:

You can also try this and its probably the best solution I found :

if(Device.RuntimePlatform == Device.iOS)
{
    //iOS stuff
}
else if(Device.RuntimePlatform == Device.Android)
{

}

这篇关于如何知道执行代码的当前操作系统/平台(Android/iOS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆