This repository has been archived by the owner on May 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 505
/
DeviceInfo.ios.tvos.watchos.cs
68 lines (60 loc) · 1.81 KB
/
DeviceInfo.ios.tvos.watchos.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Diagnostics;
#if __WATCHOS__
using WatchKit;
using UIDevice = WatchKit.WKInterfaceDevice;
#else
using UIKit;
#endif
using ObjCRuntime;
namespace Xamarin.Essentials
{
public static partial class DeviceInfo
{
static string GetModel()
{
try
{
return Essentials.Platform.GetSystemLibraryProperty("hw.machine");
}
catch (Exception)
{
Debug.WriteLine("Unable to query hardware model, returning current device model.");
}
return UIDevice.CurrentDevice.Model;
}
static string GetManufacturer() => "Apple";
static string GetDeviceName() => UIDevice.CurrentDevice.Name;
static string GetVersionString() => UIDevice.CurrentDevice.SystemVersion;
static DevicePlatform GetPlatform() =>
#if __IOS__
DevicePlatform.iOS;
#elif __TVOS__
DevicePlatform.tvOS;
#elif __WATCHOS__
DevicePlatform.watchOS;
#endif
static DeviceIdiom GetIdiom()
{
#if __WATCHOS__
return DeviceIdiom.Watch;
#else
switch (UIDevice.CurrentDevice.UserInterfaceIdiom)
{
case UIUserInterfaceIdiom.Pad:
return DeviceIdiom.Tablet;
case UIUserInterfaceIdiom.Phone:
return DeviceIdiom.Phone;
case UIUserInterfaceIdiom.TV:
return DeviceIdiom.TV;
case UIUserInterfaceIdiom.CarPlay:
case UIUserInterfaceIdiom.Unspecified:
default:
return DeviceIdiom.Unknown;
}
#endif
}
static DeviceType GetDeviceType()
=> Runtime.Arch == Arch.DEVICE ? DeviceType.Physical : DeviceType.Virtual;
}
}