Parameters

Discussion

Accessing the photo library always requires explicit permission from the user. The first time your app uses PHAsset, PHCollection, PHAssetCollection, or PHCollectionList methods to fetch content from the library, or uses one of the methods listed in Applying Changes to the Photo Library to request changes to library content, Photos automatically and asynchronously prompts the user to request authorization. Alternatively, you can call this method to prompt the user at a time of your choosing.

Important

Your app’s Info.plist file must provide a value for the NSPhotoLibraryUsageDescription key that explains to the user why your app is requesting Photos access. Apps linked on or after iOS 10 will crash if this key is not present.

After the user grants permission, the system remembers the choice for future use in your app, but the user can change this choice at any time using the Settings app. If the user has denied your app photo library access, not yet responded to the permission prompt, or cannot grant access due to restrictions, any attempts to fetch photo library content will return empty PHFetchResult objects, and any attempts to perform changes to the photo library will fail.

Tip

Use the register(_:) method to observe photo library changes before fetching content. After the user grants access to the photo library for your app, Photos sends change messages for any empty fetch results you retrieved beforehand, notifying you that library content for those fetches is now available.

This method always returns immediately. If the user has previously granted or denied photo library access permission, it executes the handler block when called; otherwise, it displays an alert and executes the block only after the user has responded to the alert.

Note

Photos may call your handler block on an arbitrary serial queue. If your handler needs to interact with user interface elements, dispatch such work to the main queue.

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.