【问题标题】:How can I find out Android and iOS versions when running a Xamarin.Forms application?运行 Xamarin.Forms 应用程序时如何找出 Android 和 iOS 版本?
【发布时间】:2020-01-12 15:46:36
【问题描述】:

有没有办法可以使用插件来做到这一点,或者我是否需要编写某种自定义渲染器?

【问题讨论】:

标签: xamarin xamarin.forms


【解决方案1】:

使用Xamarin.Essentials

// Operating System Version Number (7.0)
var version = DeviceInfo.VersionString;

// Platform (Android)
var platform = DeviceInfo.Platform;

【讨论】:

【解决方案2】:

你也可以使用Xam.Plugin.DeviceInfo

Xam.Plugin.DeviceInfo:https://www.nuget.org/packages/Xam.Plugin.DeviceInfo

代码:在 App.cs 中

// The root page of your application
        MainPage = new ContentPage
        {
            Content = new StackLayout
            {
                Padding = 50,
                VerticalOptions = LayoutOptions.Center,
                Children = {
                      new Label{ Text = "Id: " + CrossDeviceInfo.Current.Id},
                      new Label{ Text = "Model: " + CrossDeviceInfo.Current.Model},
                      new Label{ Text = "Platform: " + CrossDeviceInfo.Current.Platform},
                      new Label{ Text = "Version: " + CrossDeviceInfo.Current.Version},
                }
            }
        };

您可以从链接下载源代码以供参考。 https://github.com/jamesmontemagno/DeviceInfoPlugin

【讨论】:

    猜你喜欢
    • 2019-02-05
    • 1970-01-01
    • 2021-01-08
    • 1970-01-01
    • 2021-01-23
    • 1970-01-01
    • 1970-01-01
    • 2018-02-24
    • 2020-02-14
    相关资源
    最近更新 更多