【问题标题】:Xamarin Forms iPhone Device DetailsXamarin 窗体 iPhone 设备详细信息
【发布时间】:2020-01-14 10:55:53
【问题描述】:

我目前使用 Xamarin Forms。我需要为特定的 iPhone 版本编写一段代码。类似if (iphone == 5S) then do something

我如何在 Xamarin Studio (Forms) 中实现这一点。

【问题讨论】:

    标签: ios xamarin.ios xamarin.forms


    【解决方案1】:

    您可以使用this插件获取设备型号。一个好主意是使用Debug.WriteLine() 打印设备模型以查看该方法返回的内容。

    var model = CrossDeviceInfo.Current.Model;
    Debug.Write(model);
    if (model == "MySmartPhoneModel)
    {
        // Your method
    }
    

    【讨论】:

    • -1 CrossDeviceInfo.Current.Model 只为所有具有 iphone 习语的 iOS 设备返回“iPhone”。它没有给你确切的模型。
    【解决方案2】:

    这也可以通过使用 DependencyService 来实现。 DependencyService 允许您访问本机功能。 https://developer.xamarin.com/guides/xamarin-forms/dependency-service/

    通过使用UIDevice.CurrentDevice.Model,在您的iOS项目中,您可以检索用户设备的型号。

    【讨论】:

    • -1 没有回答这个问题。 UIDevice.CurrentDevice.Model 只为所有具有 iphone 习语的 iOS 设备(即不是 iPad)返回“iPhone”。它不会给你确切的模型。
    猜你喜欢
    • 1970-01-01
    • 2012-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-23
    • 2018-07-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多