forked from DelphiWorlds/KastriFree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDW.OSDevice.iOS.pas
108 lines (93 loc) · 3.01 KB
/
DW.OSDevice.iOS.pas
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
unit DW.OSDevice.iOS;
{*******************************************************}
{ }
{ Kastri Free }
{ }
{ DelphiWorlds Cross-Platform Library }
{ }
{*******************************************************}
{$I DW.GlobalDefines.inc}
interface
uses
// RTL
System.Types;
type
/// <remarks>
/// DO NOT ADD ANY FMX UNITS TO THESE FUNCTIONS
/// </remarks>
TPlatformOSDevice = record
public
class function GetDeviceName: string; static;
class function GetPackageID: string; static;
class function GetPackageVersion: string; static;
class function GetOffsetRect: TRectF; static;
class function GetUniqueDeviceID: string; static;
class function IsTouchDevice: Boolean; static;
end;
implementation
uses
// RTL
System.SysUtils,
// Mac
Macapi.Helpers,
// iOS
iOSapi.UIKit, iOSapi.Helpers,
// DW
DW.Macapi.Helpers;
{ TPlatformOSDevice }
class function TPlatformOSDevice.GetDeviceName: string;
begin
Result := NSStrToStr(TiOSHelper.CurrentDevice.name);
end;
class function TPlatformOSDevice.GetUniqueDeviceID: string;
begin
Result := NSStrToStr(TiOSHelper.CurrentDevice.identifierForVendor.UUIDString);
end;
class function TPlatformOSDevice.IsTouchDevice: Boolean;
begin
Result := True;
end;
class function TPlatformOSDevice.GetPackageID: string;
begin
Result := GetBundleValue('CFBundleIdentifier');
end;
class function TPlatformOSDevice.GetPackageVersion: string;
begin
Result := GetBundleValue('CFBundleVersion');
end;
class function TPlatformOSDevice.GetOffsetRect: TRectF;
const
cIPhoneXHeight = 812;
cNotchHeight = 40;
cSwipeIndicatorHeight = 24;
var
LOrientation: UIInterfaceOrientation;
begin
Result := RectF(0, 0, 0, 0);
LOrientation := TiOSHelper.SharedApplication.keyWindow.rootViewController.interfaceOrientation;
case LOrientation of
UIInterfaceOrientationPortrait: // , UIInterfaceOrientationPortraitUpsideDown - apparently there is none on iPhoneX?
begin
if TiOSHelper.MainScreen.bounds.size.height = cIPhoneXHeight then
begin
// In portrait mode, 10.2.2 accounts for the height of the notch
{$IF CompilerVersion >= 32}
Result := RectF(0, 0, 0, cSwipeIndicatorHeight);
{$ELSE}
Result := RectF(0, cNotchHeight, 0, cSwipeIndicatorHeight);
{$ENDIF}
end;
end;
UIInterfaceOrientationLandscapeLeft:
begin
if TiOSHelper.MainScreen.bounds.size.width = cIPhoneXHeight then
Result := RectF(0, 0, cNotchHeight, cSwipeIndicatorHeight);
end;
UIInterfaceOrientationLandscapeRight:
begin
if TiOSHelper.MainScreen.bounds.size.width = cIPhoneXHeight then
Result := RectF(cNotchHeight, 0, 0, cSwipeIndicatorHeight);
end;
end;
end;
end.