1

hope you can help!

Wondering how I can change code based on device version?

For example I have skia sharp code with a size integer set as below:

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

On ios 13 this looks good but on ios 11 it's way too big!

How can I change the code behind size integer based on the ios version?

Thanks!

Aluan Haddad
  • 29,886
  • 8
  • 72
  • 84
Avatar
  • 37
  • 7
  • I highly doubt your issue has anything to do with iOS version, but it is rather tied to screen density and/or scale that your code doesn't account for. – Cheesebaron Oct 11 '21 at 20:58
  • https://stackoverflow.com/questions/59705470/how-can-i-find-out-android-and-ios-versions-when-running-a-xamarin-forms-applica – Avatar Oct 19 '21 at 20:24

2 Answers2

1

For iOS

Just simply use UIDevice.CurrentDevice.CheckSystemVersion(13,0) .

It equals to @available(iOS 13, *) in Objective-C .

Refer to https://stackoverflow.com/a/21263587/8187800.

For forms

You can take a look at Xamarin.Essentials: Device Information .

// Operating System Version Number (7.0)
var version = DeviceInfo.VersionString;
ColeX
  • 14,062
  • 5
  • 43
  • 240
  • I have an error trying to use this as it says UIDevice is not available in the current context, using 'Device' instead but then then methid isn't available on this... – Avatar Oct 18 '21 at 10:53
  • I've also tried 'Version version = new Version(ObjCRuntime.Constants.Version);' but ObjCRuntime doesn't exist in context either - do I need a namespace that isn't mentioned? – Avatar Oct 18 '21 at 11:04
  • `ObjCRuntime` is the exact namespace which is included in Xamarin.iOS , check https://learn.microsoft.com/en-us/dotnet/api/objcruntime?view=xamarin-ios-sdk-12 . Have you tried my way ?Does it work or not ? – ColeX Oct 19 '21 at 01:15
  • I have, "UIDevice is not recognised"so Intellisense recommends to us Android.Hardward.Usb or Android.Bluetooth.Bluetooth class - I don't this this method works for the latest SDK 5.0.403? – Avatar Oct 19 '21 at 20:04
  • I found this but it doesn't specify version: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/platform/device – Avatar Oct 19 '21 at 20:15
  • Oh I'm sorry I thought you're coding in iOS project , the code above is used in iOS project , for forms you can use var version = DeviceInfo.VersionString; , which is included in [Xamarin.Essentials](https://learn.microsoft.com/en-us/xamarin/essentials/device-information?context=xamarin%2Fandroid&tabs=ios) plugin . – ColeX Oct 20 '21 at 02:23
0

You can get the iOS version and based on it you can set the value accordingly.

string version = UIDevice.CurrentDevice.SystemVersion;

if(version == ……….
ColeX
  • 14,062
  • 5
  • 43
  • 240
Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197
  • I have an error trying to use this as it says UIDevice is not available in the current context, using 'Device' instead but then then methid isn't available on this... – Avatar Oct 18 '21 at 10:53
  • I've also tried 'Version version = new Version(ObjCRuntime.Constants.Version);' but ObjCRuntime doesn't exist in context either - do I need a namespace that isn't mentioned? – Avatar Oct 18 '21 at 11:04