O'Reilly logo

Programming iOS 8 by Matt Neuburg

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 17. Photo Library and Image Capture

The photos and videos accessed by the user through the Photos app constitute the device’s photo library. Your app can give the user an interface for exploring this library through the UIImagePickerController class.

In addition, the Photos framework lets you access the photo library and its contents programmatically — including the ability to modify a photo’s image. You’ll need to import Photos.

The UIImagePickerController class can also be used to give the user an interface similar to the Camera app, letting the user take photos and videos on devices with the necessary hardware. At a deeper level, the AV Foundation framework (Chapter 15) provides direct control over the camera hardware. You’ll need to import AVFoundation (and probably CoreMedia).

Constants such as kUTTypeImage, referred to in this chapter, are provided by the Mobile Core Services framework; you’ll need to import MobileCoreServices.

Photo Library Authorization

Access to the photo library requires user authorization. You can use UIImagePickerController without prior authorization, as authorization will be requested for you automatically and the interface works coherently if authorization has been refused. Nevertheless, it is probably good policy for any app that’s going to need photo library access to ascertain authorization status at launch time, and to try to obtain authorization if needed. My strategy is to check the authorization status every time the root view controller ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required