Search code examples
iosavfoundationphotosframework

Crash when toggling access to Camera and Photos


I have a collection view (standard flow layout) where the first cell is displaying a live camera feed, and the rest of the cells are displaying photos from the user's library using iOS 8's new Photos Framework. Everything renders and works great.

When opening for the first time, I'm prompted for access to the Camera and to the Photos library, as expected. My app behaves fine if I select yes or no for either of the prompts.

However, if I background the app, go into Settings > Privacy > Photos|Camera and toggle access, my app crashes. When connected to Xcode, I don't get any feedback for why the app is crashing.

Unfortunately, Apple's Photos Framework examples app does the same thing.

How can I prevent this from happening? I've subscribed to notifications for AVCaptureDeviceWasConnectedNotification, AVCaptureDeviceWasDisconnectedNotification, and registerChangeObserver on PHPhotoLibrary but those never seem to get called.

Again, here are the steps using Apple's Sample app and the Simulator:

  1. In the Simulator, go to Settings > General > Reset > Reset Location & Privacy
  2. Run the app
  3. Allow the app access to your photos library
  4. Background the Sample App and open Settings
  5. Go to Privacy > Photos and toggle the setting off
  6. Watch Xcode crash

In step 3, if you decline access to your photos, and in step 5, enable access, the app will also crash.


Solution

  • It's not a crash per se. The iOS system terminates every app system wide that has requested access to the Photo Library when that privacy flag is changed (including Apple System Apps).

    This originates due to a privacy change made in iOS 6. Look at page 24 in the WWDC 2012 session on Privacy Support in iOS and OS X.