Prepare your app to ask for permission when accessing the user's photo library.
- Bundle Resources
The user must explicitly grant permission for your app to access Photos. Prepare your app for this requirement by providing justification strings. The justification string is a localizable message that you add to your app's
Info file to tell the user why your app needs access to the user's photo library. Then, when Photos prompts the user to grant permission for access, the alert displays the justification string you provided, in the language of the locale selected on the user's device.
The first time your app uses
PHCollection 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.
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, hasn't yet responded to the permission prompt, or cannot grant access due to restrictions, any attempts to fetch photo library content will return empty
PHFetch objects, and any attempts to make changes to the photo library will fail. If this method returns
PHAuthorization, you can call the
request method to prompt the user for photo library access permission.
Update Your App's Info.plist File
To use classes that interact with the Photos library, such as
PHImage, your app's
Info file must include user-facing text for the NSPhotoLibraryUsageDescription key, which the system displays when asking the user for access permission. Apps linked on or after iOS 10 will crash if this key is not present.
Observe Changes Before Fetching
register method to observe photo library changes before fetching content. After the user grants your app access to the photo library, Photos sends change messages for any empty fetch results you retrieved earlier, notifying you that library content for those fetches is now available.