Photos Framework crash: 'This application is not allowed to access Photo data.'

My crash situation is using PHCachingImageManager as a property.

fileprivate let imageManager = PHCachingImageManager()

I fix it by changing it to lazy var :

fileprivate lazy var imageManager = PHCachingImageManager()

I had the same experience. However, to reproduce it was not enough to exit the view controller and have it deallocated, but to Simulate Memory Warning in the simulator. This forced the crash.

So, my solution was to not use PHImageManager as a global variable, but to access it when need. Instead of this:

private let imageManager = PHImageManager.defaultManager()
...
imageManager.requestImageForAsset(....)

I did like this when needed:

PHImageManager.defaultManager().requestImageForAsset(....)

This is expected behaviour. Before you use any methods (like fetching, changing) of the Photos Framework, check the permission status to the Photo-Library. This is done by calling the authorizationStatus method of PHPhotoLibrary. If this method PHAuthorizationStatusNotDetermined,ask for permission using the requestAuthorization method. If authorizationStatushas a value of PHAuthorizationStatusDenied fall gracefully. The main point is to let requestAuthorization prompt for access to the Photo-Library and not the fetch methods directly.