如何知道执行代码的当前操作系统/平台(Android/iOS)

编程入门 行业动态 更新时间:2024-10-13 08:21:58
本文介绍了如何知道执行代码的当前操作系统/平台(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)

本文发布于:2023-11-14 20:04:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1588395.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:操作系统   代码   平台   iOS   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!