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

查看:57
本文介绍了如何知道执行代码的当前OS/平台(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)
{

}

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

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