15.7. Retrieving Assets from the Assets Library
Problem
You want to directly retrieve photos or videos from the photo library without the help of any built-in GUI components.
Solution
Use the Assets Library framework. Follow these steps:
Allocate and initialize an object of type
ALAssetsLibrary.Provide two block objects to the
enumerateGroupsWithTypes:usingBlock:failureBlock:instance method of the Assets Library object. The first block will retrieve all the groups associated with the type that we passed to this method. The groups will be of typeALAssetsGroup. The second block returns an error in case of failure.Use the
enumerateAssetsUsingBlock:instance method of each group object to enumerate the assets available in each group. This method takes a single parameter, a block that retrieves information on a single asset. The block that you pass as a parameter must accept three parameters, of which the first must be of typeALAsset.After retrieving the
ALAssetobjects available in each group, you can retrieve various properties of each asset, such as their type, available URLs, and so on. Retrieve these properties using thevalueForProperty:instance method of each asset of typeALAsset. The return value of this method, depending on the property passed to it, could beNSDictionary,NSString, or any other object type. We will see a few common properties that we can retrieve from each asset soon.Invoke the
defaultRepresentationinstance method of each object of typeALAssetto retrieve ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access