-
Notifications
You must be signed in to change notification settings - Fork 12
/
iOSapi.AssetsLibrary.pas
446 lines (389 loc) · 17.1 KB
/
iOSapi.AssetsLibrary.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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
{ *********************************************************** }
{ }
{ CodeGear Delphi Runtime Library }
{ }
{ Copyright(c) 2012-2014 Embarcadero Technologies, Inc. }
{ }
{ *********************************************************** }
//
// Delphi-Objective-C Bridge
// Interfaces for Cocoa framework AssetsLibrary
//
unit iOSapi.AssetsLibrary;
interface
uses
Macapi.CoreFoundation,
Macapi.CoreServices,
Macapi.Dispatch,
Macapi.Foundation,
Macapi.Mach,
Macapi.ObjCRuntime,
Macapi.ObjectiveC,
Macapi.QuartzCore,
iOSapi.CocoaTypes,
iOSapi.CoreGraphics,
iOSapi.Foundation;
const
ALAssetOrientationUp = 0;
ALAssetOrientationDown = 1;
ALAssetOrientationLeft = 2;
ALAssetOrientationRight = 3;
ALAssetOrientationUpMirrored = 4;
ALAssetOrientationDownMirrored = 5;
ALAssetOrientationLeftMirrored = 6;
ALAssetOrientationRightMirrored = 7;
ALAssetsGroupLibrary = (1 shl 0);
ALAssetsGroupAlbum = (1 shl 1);
ALAssetsGroupEvent = (1 shl 2);
ALAssetsGroupFaces = (1 shl 3);
ALAssetsGroupSavedPhotos = (1 shl 4);
ALAssetsGroupPhotoStream = (1 shl 5);
ALAssetsGroupAll = 4294967295;
ALAuthorizationStatusNotDetermined = 0;
ALAuthorizationStatusRestricted = 1;
ALAuthorizationStatusDenied = 2;
ALAuthorizationStatusAuthorized = 3;
ALAssetsLibraryUnknownError = -1;
ALAssetsLibraryWriteFailedError = -3300;
ALAssetsLibraryWriteBusyError = -3301;
ALAssetsLibraryWriteInvalidDataError = -3302;
ALAssetsLibraryWriteIncompatibleDataError = -3303;
ALAssetsLibraryWriteDataEncodingError = -3304;
ALAssetsLibraryWriteDiskSpaceError = -3305;
ALAssetsLibraryDataUnavailableError = -3310;
ALAssetsLibraryAccessUserDeniedError = -3311;
ALAssetsLibraryAccessGloballyDeniedError = -3312;
type
// ===== Forward declarations =====
{$M+}
ALAsset = interface;
ALAssetsGroup = interface;
ALAssetsLibrary = interface;
ALAssetRepresentation = interface;
ALAssetsFilter = interface;
// ===== Framework typedefs =====
{$M+}
NSInteger = Integer;
ALAssetOrientation = NSInteger;
NSUInteger = Cardinal;
ALAssetsGroupType = NSUInteger;
ALAuthorizationStatus = NSInteger;
ALAssetsLibraryGroupsEnumerationResultsBlock = procedure
(param1: ALAssetsGroup; param2: PBoolean) of object;
ALAssetsLibraryAssetForURLResultBlock = procedure(param1: ALAsset) of object;
ALAssetsLibraryGroupResultBlock = procedure(param1: ALAssetsGroup) of object;
ALAssetsLibraryAccessFailureBlock = procedure(param1: NSError) of object;
ALAssetsLibraryWriteImageCompletionBlock = procedure(param1: NSURL;
param2: NSError) of object;
ALAssetsLibraryWriteVideoCompletionBlock = procedure(param1: NSURL;
param2: NSError) of object;
CGImageRef = Pointer;
ALAssetsGroupEnumerationResultsBlock = procedure(param1: ALAsset;
param2: NSUInteger; param3: PBoolean) of object;
NSEnumerationOptions = NSUInteger;
CGFloat = Single;
CGSize = CGSize = record width: CGFloat;
height:
CGFloat;
end;
PCGSize = ^CGSize;;
// ===== Interface declarations =====
ALAssetClass = interface(NSObjectClass)
['{D09ED50F-97E6-4B43-A084-8223DFF91D0F}']
end;
ALAsset = interface(NSObject)['{2EBE2D03-13BA-43BE-A4D5-F734AA593D6E}']
function valueForProperty(&property: NSString): Pointer;
cdecl;
function defaultRepresentation: ALAssetRepresentation; cdecl;
function representationForUTI(representationUTI: NSString)
: ALAssetRepresentation; cdecl;
function thumbnail: CGImageRef; cdecl;
function aspectRatioThumbnail: CGImageRef; cdecl;
procedure writeModifiedImageDataToSavedPhotosAlbum(imageData: NSData;
metadata: NSDictionary;
completionBlock: ALAssetsLibraryWriteImageCompletionBlock); cdecl;
procedure writeModifiedVideoAtPathToSavedPhotosAlbum
(videoPathURL: NSURL;
completionBlock: ALAssetsLibraryWriteVideoCompletionBlock); cdecl;
function originalAsset: ALAsset; cdecl;
function isEditable: Boolean; cdecl;
procedure setImageData(imageData: NSData;
metadata: NSDictionary;
completionBlock
: ALAssetsLibraryWriteImageCompletionBlock); cdecl;
procedure setVideoAtPath(videoPathURL: NSURL;
completionBlock
: ALAssetsLibraryWriteVideoCompletionBlock); cdecl;
end;
TALAsset = class(TOCGenericImport<ALAssetClass, ALAsset>)
end;
PALAsset = Pointer;
ALAssetsGroupClass = interface(NSObjectClass)
['{2CD643FA-7485-47BF-A12C-A167C8059806}']
end;
ALAssetsGroup = interface(NSObject)
['{97039DCD-26B5-496F-AF35-8F7F94826C00}']
function valueForProperty(&property: NSString): Pointer;
cdecl;
function posterImage: CGImageRef; cdecl;
procedure setAssetsFilter(filter: ALAssetsFilter); cdecl;
function numberOfAssets: NSInteger; cdecl;
procedure enumerateAssetsUsingBlock(enumerationBlock
: ALAssetsGroupEnumerationResultsBlock); cdecl;
procedure enumerateAssetsWithOptions
(options: NSEnumerationOptions;
usingBlock: ALAssetsGroupEnumerationResultsBlock); cdecl;
procedure enumerateAssetsAtIndexes(indexSet: NSIndexSet;
options: NSEnumerationOptions;
usingBlock: ALAssetsGroupEnumerationResultsBlock); cdecl;
function isEditable: Boolean; cdecl;
function addAsset(asset: ALAsset): Boolean; cdecl;
end;
TALAssetsGroup = class
(TOCGenericImport<ALAssetsGroupClass, ALAssetsGroup>)
end;
PALAssetsGroup = Pointer;
ALAssetsLibraryClass = interface(NSObjectClass)
['{C8203772-CA30-4065-976B-31BE3E00781F}']
{ class } function authorizationStatus: ALAuthorizationStatus;
cdecl;
{ class } procedure disableSharedPhotoStreamsSupport; cdecl;
end;
ALAssetsLibrary = interface(NSObject)
['{A4FD0B1C-2CED-483D-9697-0D3C01E81BDC}']
procedure enumerateGroupsWithTypes(types: ALAssetsGroupType;
usingBlock: ALAssetsLibraryGroupsEnumerationResultsBlock;
failureBlock: ALAssetsLibraryAccessFailureBlock);
cdecl;
procedure assetForURL(assetURL: NSURL;
resultBlock: ALAssetsLibraryAssetForURLResultBlock;
failureBlock: ALAssetsLibraryAccessFailureBlock); cdecl;
procedure groupForURL(groupURL: NSURL;
resultBlock: ALAssetsLibraryGroupResultBlock;
failureBlock: ALAssetsLibraryAccessFailureBlock); cdecl;
procedure addAssetsGroupAlbumWithName(name: NSString;
resultBlock: ALAssetsLibraryGroupResultBlock;
failureBlock: ALAssetsLibraryAccessFailureBlock); cdecl;
[MethodName
('writeImageToSavedPhotosAlbum:orientation:completionBlock:')
]
procedure writeImageToSavedPhotosAlbumOrientationCompletionBlock
(imageRef: CGImageRef; orientation: ALAssetOrientation;
completionBlock
: ALAssetsLibraryWriteImageCompletionBlock); cdecl;
[MethodName
('writeImageToSavedPhotosAlbum:metadata:completionBlock:')
]
procedure writeImageToSavedPhotosAlbumMetadataCompletionBlock
(imageRef: CGImageRef; metadata: NSDictionary;
completionBlock
: ALAssetsLibraryWriteImageCompletionBlock); cdecl;
procedure writeImageDataToSavedPhotosAlbum
(imageData: NSData; metadata: NSDictionary;
completionBlock
: ALAssetsLibraryWriteImageCompletionBlock); cdecl;
procedure writeVideoAtPathToSavedPhotosAlbum
(videoPathURL: NSURL;
completionBlock
: ALAssetsLibraryWriteVideoCompletionBlock); cdecl;
function videoAtPathIsCompatibleWithSavedPhotosAlbum
(videoPathURL: NSURL): Boolean; cdecl;
end;
TALAssetsLibrary = class
(TOCGenericImport<ALAssetsLibraryClass,
ALAssetsLibrary>)
end;
PALAssetsLibrary = Pointer;
ALAssetRepresentationClass = interface(NSObjectClass)
['{05F47CD4-7913-42D0-B263-4A934D06391D}']
end;
ALAssetRepresentation = interface(NSObject)
['{BDBD62C6-8836-4E67-B667-28B873E0C85D}']
function UTI: NSString;
cdecl;
function dimensions: CGSize; cdecl;
function size: Int64; cdecl;
function getBytes(buffer: PByte; fromOffset: Int64;
length: NSUInteger; error: NSError): NSUInteger; cdecl;
function fullResolutionImage: CGImageRef; cdecl;
function CGImageWithOptions(options: NSDictionary)
: CGImageRef; cdecl;
function fullScreenImage: CGImageRef; cdecl;
function url: NSURL; cdecl;
function metadata: NSDictionary; cdecl;
function orientation
: ALAssetOrientation; cdecl;
function scale: Single; cdecl;
function filename: NSString; cdecl;
end;
TALAssetRepresentation = class
(TOCGenericImport<
ALAssetRepresentationClass,
ALAssetRepresentation>)
end;
PALAssetRepresentation = Pointer;
ALAssetsFilterClass = interface(NSObjectClass)
['{3F27E60B-49E3-4DA6-BF77-4DD575E4E0BC}']
{ class } function allPhotos: ALAssetsFilter;
cdecl;
{ class } function allVideos
: ALAssetsFilter; cdecl;
{ class } function allAssets
: ALAssetsFilter; cdecl;
end;
ALAssetsFilter = interface(NSObject)
['{2346F7AA-40DC-452B-A0B1-62430BC09321}']
end;
TALAssetsFilter = class
(TOCGenericImport<ALAssetsFilterClass,
ALAssetsFilter>)
end;
PALAssetsFilter = Pointer;
// ===== Exported string consts =====
function ALAssetsLibraryChangedNotification: NSString;
function ALAssetLibraryUpdatedAssetsKey: NSString;
function ALAssetLibraryInsertedAssetGroupsKey
: NSString;
function ALAssetLibraryUpdatedAssetGroupsKey
: NSString;
function ALAssetLibraryDeletedAssetGroupsKey
: NSString;
function ALAssetsLibraryErrorDomain: NSString;
function ALErrorInvalidProperty: NSString;
function ALAssetPropertyType: NSString;
function ALAssetPropertyLocation
: NSString;
function ALAssetPropertyDuration
: NSString;
function ALAssetPropertyOrientation
: NSString;
function ALAssetPropertyDate: NSString;
function ALAssetPropertyRepresentations
: NSString;
function ALAssetPropertyURLs: NSString;
function ALAssetPropertyAssetURL
: NSString;
function ALAssetTypePhoto: NSString;
function ALAssetTypeVideo: NSString;
function ALAssetTypeUnknown: NSString;
function ALAssetsGroupPropertyName
: NSString;
function ALAssetsGroupPropertyType
: NSString;
function ALAssetsGroupPropertyPersistentID
: NSString;
function ALAssetsGroupPropertyURL
: NSString;
// ===== External functions =====
const
libAssetsLibrary =
'/System/Library/Frameworks/AssetsLibrary.framework/AssetsLibrary';
implementation
{$IF defined(IOS) and NOT defined(CPUARM)}
uses
Posix.Dlfcn;
var
AssetsLibraryModule: THandle;
{$ENDIF IOS}
function ALAssetsLibraryChangedNotification: NSString;
begin
Result := CocoaNSStringConst(libAssetsLibrary,
'ALAssetsLibraryChangedNotification');
end;
function ALAssetLibraryUpdatedAssetsKey: NSString;
begin
Result := CocoaNSStringConst(libAssetsLibrary,
'ALAssetLibraryUpdatedAssetsKey');
end;
function ALAssetLibraryInsertedAssetGroupsKey: NSString;
begin
Result := CocoaNSStringConst(libAssetsLibrary,
'ALAssetLibraryInsertedAssetGroupsKey');
end;
function ALAssetLibraryUpdatedAssetGroupsKey: NSString;
begin
Result := CocoaNSStringConst(libAssetsLibrary,
'ALAssetLibraryUpdatedAssetGroupsKey');
end;
function ALAssetLibraryDeletedAssetGroupsKey: NSString;
begin
Result := CocoaNSStringConst(libAssetsLibrary,
'ALAssetLibraryDeletedAssetGroupsKey');
end;
function ALAssetsLibraryErrorDomain: NSString;
begin
Result := CocoaNSStringConst(libAssetsLibrary, 'ALAssetsLibraryErrorDomain');
end;
function ALErrorInvalidProperty: NSString;
begin
Result := CocoaNSStringConst(libAssetsLibrary, 'ALErrorInvalidProperty');
end;
function ALAssetPropertyType: NSString;
begin
Result := CocoaNSStringConst(libAssetsLibrary, 'ALAssetPropertyType');
end;
function ALAssetPropertyLocation: NSString;
begin
Result := CocoaNSStringConst(libAssetsLibrary, 'ALAssetPropertyLocation');
end;
function ALAssetPropertyDuration: NSString;
begin
Result := CocoaNSStringConst(libAssetsLibrary, 'ALAssetPropertyDuration');
end;
function ALAssetPropertyOrientation: NSString;
begin
Result := CocoaNSStringConst(libAssetsLibrary, 'ALAssetPropertyOrientation');
end;
function ALAssetPropertyDate: NSString;
begin
Result := CocoaNSStringConst(libAssetsLibrary, 'ALAssetPropertyDate');
end;
function ALAssetPropertyRepresentations: NSString;
begin
Result := CocoaNSStringConst(libAssetsLibrary,
'ALAssetPropertyRepresentations');
end;
function ALAssetPropertyURLs: NSString;
begin
Result := CocoaNSStringConst(libAssetsLibrary, 'ALAssetPropertyURLs');
end;
function ALAssetPropertyAssetURL: NSString;
begin
Result := CocoaNSStringConst(libAssetsLibrary, 'ALAssetPropertyAssetURL');
end;
function ALAssetTypePhoto: NSString;
begin
Result := CocoaNSStringConst(libAssetsLibrary, 'ALAssetTypePhoto');
end;
function ALAssetTypeVideo: NSString;
begin
Result := CocoaNSStringConst(libAssetsLibrary, 'ALAssetTypeVideo');
end;
function ALAssetTypeUnknown: NSString;
begin
Result := CocoaNSStringConst(libAssetsLibrary, 'ALAssetTypeUnknown');
end;
function ALAssetsGroupPropertyName: NSString;
begin
Result := CocoaNSStringConst(libAssetsLibrary, 'ALAssetsGroupPropertyName');
end;
function ALAssetsGroupPropertyType: NSString;
begin
Result := CocoaNSStringConst(libAssetsLibrary, 'ALAssetsGroupPropertyType');
end;
function ALAssetsGroupPropertyPersistentID: NSString;
begin
Result := CocoaNSStringConst(libAssetsLibrary,
'ALAssetsGroupPropertyPersistentID');
end;
function ALAssetsGroupPropertyURL: NSString;
begin
Result := CocoaNSStringConst(libAssetsLibrary, 'ALAssetsGroupPropertyURL');
end;
{$IF defined(IOS) and NOT defined(CPUARM)}
initialization
AssetsLibraryModule := dlopen(MarshaledAString(libAssetsLibrary), RTLD_LAZY);
finalization
dlclose(AssetsLibraryModule);
{$ENDIF IOS}
end.