The Assets Library Framework

The Assets Library framework, introduced in iOS 4, does for the photo library roughly what the Media Player framework does for the music library (Chapter 29), letting your code explore the library’s contents. You’ll need to link to AssetsLibrary.framework and import <AssetsLibrary/AssetsLibrary.h>. One obvious use of the Assets Library framework might be to implement your own interface for letting the user choose an image in a way that transcends the limitations of UIImagePickerController.


You might not be able to explore the photo library in this way; instead, you might get a “Global denied access” error, because the user must explicitly grant permission to access the library. If the user has never done that, the interface for giving such permission (Figure 30-1) requires that Location Services be turned on. So if the user has never given permission and Location Services is off, or if Location Services is on and the user refuses permission, you are blocked; your code must always be prepared for this possibility. (In my tests, even when I tapped OK in the Figure 30-1 interface, my code seemed to halt; I didn’t get an error notification, but my code didn’t access the photo library either. Things worked fine the next time my code ran. This feels like a bug.)

The user might see this

Figure 30-1. The user might see this

A photo or video in the photo library is an ALAsset. Like ...

Get Programming iOS 4 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.