iOS 8‘s broader camera privacy enforcement has caught many photo apps off guard. For too long, apps have just grabbed a UIImagePickerController and hoped for the best. After all, if isSourceTypeAvailable: or isCameraDeviceAvailable: answers YES, what could possibly go wrong?
Well, a lot. Now, if the user dismisses the first “Would Like to Access the Camera” prompt, bad things happen until the user changes the camera privacy settings. Without access, various apps (including my own) running under the iOS 8 betas have responded with black capture screens, crashes, and other ugliness.
The fix, of course, is to check further for access and gracefully handle denials: disable camera buttons and display a message. Here’s one way to check:
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
AVCaptureDevice *cameraDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; AVCaptureDeviceInput *deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:cameraDevice error:&error];
…will give a more helpful error message in the NSError’s localizedFailureReason, such as “This app is not authorized to use the Back Camera.”
Who knows; maybe we’ll start getting failure reasons of “excessive selfies.” We can hope.