forked from FMXExpress/ios-object-pascal-wrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iOSapi.Accounts.pas
307 lines (251 loc) · 9.06 KB
/
iOSapi.Accounts.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
{ *********************************************************** }
{ }
{ CodeGear Delphi Runtime Library }
{ }
{ Copyright(c) 2012-2014 Embarcadero Technologies, Inc. }
{ }
{ *********************************************************** }
//
// Delphi-Objective-C Bridge
// Interfaces for Cocoa framework Accounts
//
unit iOSapi.Accounts;
interface
uses
Macapi.CoreFoundation,
Macapi.CoreServices,
Macapi.Dispatch,
Macapi.Foundation,
Macapi.Mach,
Macapi.ObjCRuntime,
Macapi.ObjectiveC,
Macapi.QuartzCore,
iOSapi.CocoaTypes,
iOSapi.Foundation;
const
ACAccountCredentialRenewResultRenewed = 0;
ACAccountCredentialRenewResultRejected = 1;
ACAccountCredentialRenewResultFailed = 2;
ACErrorUnknown = 1;
ACErrorAccountMissingRequiredProperty = 2;
ACErrorAccountAuthenticationFailed = 3;
ACErrorAccountTypeInvalid = 4;
ACErrorAccountAlreadyExists = 5;
ACErrorAccountNotFound = 6;
ACErrorPermissionDenied = 7;
ACErrorAccessInfoInvalid = 8;
ACErrorClientPermissionDenied = 9;
ACErrorAccessDeniedByProtectionPolicy = 10;
ACErrorCredentialNotFound = 11;
ACErrorFetchCredentialFailed = 12;
ACErrorStoreCredentialFailed = 13;
ACErrorRemoveCredentialFailed = 14;
ACErrorUpdatingNonexistentAccount = 15;
ACErrorInvalidClientBundleID = 16;
ACErrorDeniedByPlugin = 17;
ACErrorCoreDataSaveFailed = 18;
ACErrorFailedSerializingAccountInfo = 19;
ACErrorInvalidCommand = 20;
ACErrorMissingTransportMessageID = 21;
ACErrorCredentialItemNotFound = 22;
ACErrorCredentialItemNotExpired = 23;
type
// ===== Forward declarations =====
{$M+}
ACAccountType = interface;
ACAccountCredential = interface;
ACAccount = interface;
ACAccountStore = interface;
// ===== Framework typedefs =====
{$M+}
NSInteger = Integer;
ACAccountCredentialRenewResult = NSInteger;
ACAccountStoreSaveCompletionHandler = procedure(param1: Boolean;
param2: NSError) of object;
ACAccountStoreRemoveCompletionHandler = procedure(param1: Boolean;
param2: NSError) of object;
ACAccountStoreRequestAccessCompletionHandler = procedure(param1: Boolean;
param2: NSError) of object;
ACAccountStoreCredentialRenewalHandler = procedure
(param1: ACAccountCredentialRenewResult; param2: NSError) of object;
ACErrorCode = Cardinal;
// ===== Interface declarations =====
ACAccountTypeClass = interface(NSObjectClass)
['{829694E1-7A28-418B-8E8A-00FDFD40A51B}']
end;
ACAccountType = interface(NSObject)
['{479922BC-DCFD-4883-BDC6-0687172438A4}']
function accountTypeDescription: NSString; cdecl;
function identifier: NSString; cdecl;
function accessGranted: Boolean; cdecl;
end;
TACAccountType = class(TOCGenericImport<ACAccountTypeClass, ACAccountType>)
end;
PACAccountType = Pointer;
ACAccountCredentialClass = interface(NSObjectClass)
['{53A85F29-8D86-4445-9268-346B736C3029}']
end;
ACAccountCredential = interface(NSObject)
['{224D30B9-4618-4D7F-9F17-07361E444F40}']
function initWithOAuthToken(token: NSString; tokenSecret: NSString)
: Pointer { instancetype }; cdecl;
function initWithOAuth2Token(token: NSString; refreshToken: NSString;
expiryDate: NSDate): Pointer { instancetype }; cdecl;
procedure setOauthToken(oauthToken: NSString); cdecl;
function oauthToken: NSString; cdecl;
end;
TACAccountCredential = class(TOCGenericImport<ACAccountCredentialClass,
ACAccountCredential>)
end;
PACAccountCredential = Pointer;
ACAccountClass = interface(NSObjectClass)
['{718EF0A3-D30E-4570-A1D8-252B2392A4C8}']
end;
ACAccount = interface(NSObject)
['{4FE256F6-3201-48A8-9ABA-547A4BF03D66}']
function initWithAccountType(&type: ACAccountType)
: Pointer { instancetype }; cdecl;
function identifier: NSString; cdecl;
procedure setAccountType(accountType: ACAccountType); cdecl;
function accountType: ACAccountType; cdecl;
procedure setAccountDescription(accountDescription: NSString); cdecl;
function accountDescription: NSString; cdecl;
procedure setUsername(username: NSString); cdecl;
function username: NSString; cdecl;
function userFullName: NSString; cdecl;
procedure setCredential(credential: ACAccountCredential); cdecl;
function credential: ACAccountCredential; cdecl;
end;
TACAccount = class(TOCGenericImport<ACAccountClass, ACAccount>)
end;
PACAccount = Pointer;
ACAccountStoreClass = interface(NSObjectClass)
['{3AECC229-444C-4A62-99CA-721618B142B6}']
end;
ACAccountStore = interface(NSObject)
['{57B09B8C-01D7-42AA-BBA1-D8EA8A252067}']
function Accounts: NSArray; cdecl;
function accountWithIdentifier(identifier: NSString): ACAccount; cdecl;
function accountTypeWithAccountTypeIdentifier(typeIdentifier: NSString)
: ACAccountType; cdecl;
function accountsWithAccountType(accountType: ACAccountType)
: NSArray; cdecl;
procedure saveAccount(account: ACAccount;
withCompletionHandler: ACAccountStoreSaveCompletionHandler); cdecl;
[MethodName('requestAccessToAccountsWithType:withCompletionHandler:')]
procedure requestAccessToAccountsWithTypeWithCompletionHandler
(accountType: ACAccountType;
withCompletionHandler
: ACAccountStoreRequestAccessCompletionHandler); cdecl;
[MethodName('requestAccessToAccountsWithType:options:completion:')]
procedure requestAccessToAccountsWithTypeOptionsCompletion
(accountType: ACAccountType; options: NSDictionary;
completion: ACAccountStoreRequestAccessCompletionHandler); cdecl;
procedure renewCredentialsForAccount(account: ACAccount;
completion: ACAccountStoreCredentialRenewalHandler); cdecl;
procedure removeAccount(account: ACAccount;
withCompletionHandler: ACAccountStoreRemoveCompletionHandler); cdecl;
end;
TACAccountStore = class(TOCGenericImport<ACAccountStoreClass, ACAccountStore>)
end;
PACAccountStore = Pointer;
// ===== Exported string consts =====
function ACAccountStoreDidChangeNotification: NSString;
function ACAccountTypeIdentifierTwitter: NSString;
function ACAccountTypeIdentifierFacebook: NSString;
function ACAccountTypeIdentifierSinaWeibo: NSString;
function ACAccountTypeIdentifierTencentWeibo: NSString;
function ACAccountTypeIdentifierLinkedIn: NSString;
function ACFacebookAppIdKey: NSString;
function ACFacebookPermissionsKey: NSString;
function ACFacebookAudienceKey: NSString;
function ACFacebookAudienceEveryone: NSString;
function ACFacebookAudienceFriends: NSString;
function ACFacebookAudienceOnlyMe: NSString;
function ACLinkedInAppIdKey: NSString;
function ACLinkedInPermissionsKey: NSString;
function ACTencentWeiboAppIdKey: NSString;
function ACErrorDomain: NSString;
// ===== External functions =====
const
libAccounts = '/System/Library/Frameworks/Accounts.framework/Accounts';
implementation
{$IF defined(IOS) and NOT defined(CPUARM)}
uses
Posix.Dlfcn;
var
AccountsModule: THandle;
{$ENDIF IOS}
function ACAccountStoreDidChangeNotification: NSString;
begin
Result := CocoaNSStringConst(libAccounts,
'ACAccountStoreDidChangeNotification');
end;
function ACAccountTypeIdentifierTwitter: NSString;
begin
Result := CocoaNSStringConst(libAccounts, 'ACAccountTypeIdentifierTwitter');
end;
function ACAccountTypeIdentifierFacebook: NSString;
begin
Result := CocoaNSStringConst(libAccounts, 'ACAccountTypeIdentifierFacebook');
end;
function ACAccountTypeIdentifierSinaWeibo: NSString;
begin
Result := CocoaNSStringConst(libAccounts, 'ACAccountTypeIdentifierSinaWeibo');
end;
function ACAccountTypeIdentifierTencentWeibo: NSString;
begin
Result := CocoaNSStringConst(libAccounts,
'ACAccountTypeIdentifierTencentWeibo');
end;
function ACAccountTypeIdentifierLinkedIn: NSString;
begin
Result := CocoaNSStringConst(libAccounts, 'ACAccountTypeIdentifierLinkedIn');
end;
function ACFacebookAppIdKey: NSString;
begin
Result := CocoaNSStringConst(libAccounts, 'ACFacebookAppIdKey');
end;
function ACFacebookPermissionsKey: NSString;
begin
Result := CocoaNSStringConst(libAccounts, 'ACFacebookPermissionsKey');
end;
function ACFacebookAudienceKey: NSString;
begin
Result := CocoaNSStringConst(libAccounts, 'ACFacebookAudienceKey');
end;
function ACFacebookAudienceEveryone: NSString;
begin
Result := CocoaNSStringConst(libAccounts, 'ACFacebookAudienceEveryone');
end;
function ACFacebookAudienceFriends: NSString;
begin
Result := CocoaNSStringConst(libAccounts, 'ACFacebookAudienceFriends');
end;
function ACFacebookAudienceOnlyMe: NSString;
begin
Result := CocoaNSStringConst(libAccounts, 'ACFacebookAudienceOnlyMe');
end;
function ACLinkedInAppIdKey: NSString;
begin
Result := CocoaNSStringConst(libAccounts, 'ACLinkedInAppIdKey');
end;
function ACLinkedInPermissionsKey: NSString;
begin
Result := CocoaNSStringConst(libAccounts, 'ACLinkedInPermissionsKey');
end;
function ACTencentWeiboAppIdKey: NSString;
begin
Result := CocoaNSStringConst(libAccounts, 'ACTencentWeiboAppIdKey');
end;
function ACErrorDomain: NSString;
begin
Result := CocoaNSStringConst(libAccounts, 'ACErrorDomain');
end;
{$IF defined(IOS) and NOT defined(CPUARM)}
initialization
AccountsModule := dlopen(MarshaledAString(libAccounts), RTLD_LAZY);
finalization
dlclose(AccountsModule);
{$ENDIF IOS}
end.