forked from FMXExpress/ios-object-pascal-wrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiOSapi.LocalAuthentication.pas
149 lines (119 loc) · 3.98 KB
/
iOSapi.LocalAuthentication.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
{ *********************************************************** }
{ }
{ CodeGear Delphi Runtime Library }
{ }
{ Copyright(c) 2012-2014 Embarcadero Technologies, Inc. }
{ }
{ *********************************************************** }
//
// Delphi-Objective-C Bridge
// Interfaces for Cocoa framework LocalAuthentication
//
unit iOSapi.LocalAuthentication;
interface
uses
Macapi.CoreFoundation,
Macapi.CoreServices,
Macapi.Dispatch,
Macapi.Foundation,
Macapi.Mach,
Macapi.ObjCRuntime,
Macapi.ObjectiveC,
Macapi.QuartzCore,
iOSapi.CocoaTypes,
iOSapi.Foundation,
iOSapi.Security;
const
LAPolicyDeviceOwnerAuthenticationWithBiometrics = 1;
LAPolicyDeviceOwnerAuthentication = 2;
LACredentialTypeApplicationPassword = 0;
LAAccessControlOperationCreateItem = 0;
LAAccessControlOperationUseItem = 1;
LAAccessControlOperationCreateKey = 2;
LAAccessControlOperationUseKeySign = 3;
LAErrorAuthenticationFailed = -1;
LAErrorUserCancel = -2;
LAErrorUserFallback = -3;
LAErrorSystemCancel = -4;
LAErrorPasscodeNotSet = -5;
LAErrorTouchIDNotAvailable = -6;
LAErrorTouchIDNotEnrolled = -7;
LAErrorTouchIDLockout = -8;
LAErrorAppCancel = -9;
LAErrorInvalidContext = -10;
type
// ===== Forward declarations =====
{$M+}
LAContext = interface;
// ===== Framework typedefs =====
{$M+}
NSInteger = Integer;
LAPolicy = NSInteger;
NSTimeInterval = Double;
TLocalAuthenticationReply = procedure(param1: Boolean; param2: NSError)
of object;
LACredentialType = NSInteger;
SecAccessControlRef = Pointer;
LAAccessControlOperation = NSInteger;
LAError = NSInteger;
// ===== Interface declarations =====
LAContextClass = interface(NSObjectClass)
['{90938FAC-60C5-43A2-A3C8-3CEA6626BA7C}']
end;
LAContext = interface(NSObject)
['{1E809F4B-33BA-4683-84FB-80345F1D89DE}']
function canEvaluatePolicy(policy: LAPolicy; error: NSError)
: Boolean; cdecl;
procedure evaluatePolicy(policy: LAPolicy; localizedReason: NSString;
reply: TLocalAuthenticationReply); cdecl;
procedure invalidate; cdecl;
function setCredential(credential: NSData; &type: LACredentialType)
: Boolean; cdecl;
function isCredentialSet(&type: LACredentialType): Boolean; cdecl;
procedure evaluateAccessControl(accessControl: SecAccessControlRef;
operation: LAAccessControlOperation; localizedReason: NSString;
reply: TLocalAuthenticationReply); cdecl;
procedure setLocalizedFallbackTitle(localizedFallbackTitle
: NSString); cdecl;
function localizedFallbackTitle: NSString; cdecl;
procedure setMaxBiometryFailures(maxBiometryFailures: NSNumber); cdecl;
function maxBiometryFailures: NSNumber; cdecl;
function evaluatedPolicyDomainState: NSData; cdecl;
procedure setTouchIDAuthenticationAllowableReuseDuration
(touchIDAuthenticationAllowableReuseDuration: NSTimeInterval); cdecl;
function touchIDAuthenticationAllowableReuseDuration: NSTimeInterval; cdecl;
end;
TLAContext = class(TOCGenericImport<LAContextClass, LAContext>)
end;
PLAContext = Pointer;
// ===== Exported string consts =====
function LATouchIDAuthenticationMaximumAllowableReuseDuration: Pointer;
function LAErrorDomain: NSString;
// ===== External functions =====
const
libLocalAuthentication =
'/System/Library/Frameworks/LocalAuthentication.framework/LocalAuthentication';
implementation
{$IF defined(IOS) and NOT defined(CPUARM)}
uses
Posix.Dlfcn;
var
LocalAuthenticationModule: THandle;
{$ENDIF IOS}
function LAErrorDomain: NSString;
begin
Result := CocoaNSStringConst(libLocalAuthentication, 'LAErrorDomain');
end;
function LATouchIDAuthenticationMaximumAllowableReuseDuration: Pointer;
begin
Result := CocoaPointerConst(libLocalAuthentication,
'LATouchIDAuthenticationMaximumAllowableReuseDuration');
end;
{$IF defined(IOS) and NOT defined(CPUARM)}
initialization
LocalAuthenticationModule := dlopen(MarshaledAString(libLocalAuthentication),
RTLD_LAZY);
finalization
dlclose(LocalAuthenticationModule);
{$ENDIF IOS}
end.