13.7. Retrieving Assets from the Assets Library
You want to directly retrieve photos or videos from the Photo Library without the help of any built-in GUI components.
Use the Assets Library framework. Follow these steps:
Allocate and initialize an object of type
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 type
ALAssetsGroup. The second block returns an error in case of failure.
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 type
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 the
valueForProperty:instance method of each asset of type
ALAsset. The return value of this method, depending on the property passed to it, could be
NSString, or any other object type. We will see a few common properties that we can retrieve from each asset soon.
defaultRepresentationinstance method of each object of type
ALAssetto retrieve ...