【问题标题】:Cross compatible differences xamarin / C#交叉兼容差异 xamarin / C#
【发布时间】:2021-11-29 18:35:10
【问题描述】:

希望你能帮忙!

想知道如何根据设备版本更改代码?

例如,我有一个大小整数设置如下的skia sharp代码:

int size = Math.Min(180, 180);

在 ios 13 上这看起来不错,但在 ios 11 上它太大了!

如何根据ios版本更改size integer后面的代码?

谢谢!

【问题讨论】:

标签: c# ios xamarin code-behind


【解决方案1】:

对于 iOS

只需使用 UIDevice.CurrentDevice.CheckSystemVersion(13,0) 即可。

它等于 Objective-C 中的@available(iOS 13, *)

请参阅https://stackoverflow.com/a/21263587/8187800

表格

你可以看看Xamarin.Essentials: Device Information

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

【讨论】:

  • 我在尝试使用它时出错,因为它说 UIDevice 在当前上下文中不可用,而是使用 'Device' 但随后 methid 在此不可用...
  • 我也试过 'Version version = new Version(ObjCRuntime.Constants.Version);'但 ObjCRuntime 也不存在于上下文中 - 我需要一个未提及的命名空间吗?
  • ObjCRuntime 是 Xamarin.iOS 中包含的确切命名空间,请检查 docs.microsoft.com/en-us/dotnet/api/… 。你试过我的方法吗?行不行?
  • 我有,“UIDevice 未被识别”所以 Intellisense 向我们推荐 Android.Hardward.Usb 或 Android.Bluetooth.Bluetooth 类 - 我不这种方法适用于最新的 SDK 5.0.403 ?
  • 我找到了这个,但它没有指定版本:docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/device
【解决方案2】:

您可以获取 iOS 版本,并根据它设置相应的值。

string version = UIDevice.CurrentDevice.SystemVersion;

if(version == ……….

【讨论】:

  • 我在尝试使用它时出错,因为它说 UIDevice 在当前上下文中不可用,而是使用 'Device' 但随后 methid 在此不可用...
  • 我也试过 'Version version = new Version(ObjCRuntime.Constants.Version);'但 ObjCRuntime 也不存在于上下文中 - 我需要一个未提及的命名空间吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-31
  • 2011-10-12
  • 2021-03-20
  • 2016-12-11
  • 1970-01-01
  • 2023-04-07
相关资源
最近更新 更多