Cover by Vandad Nahavandipoor

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

11.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:

  1. Allocate and initialize an object of type ALAssetsLibrary.

  2. 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.

  3. 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 type ALAsset.

  4. After retrieving the ALAsset objects 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 NSDictionary, NSString, or any other object type. We will see a few common properties that we can retrieve from each asset soon.

  5. Invoke the defaultRepresentation instance method of each object of type ALAsset to retrieve ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required