Respect user privacy by seeking permission to capture and store photos, audio, and video.
In iOS, the user must explicitly grant permission for each app to access cameras and microphones. Before your app can use the capture system for the first time, iOS shows an alert asking the user to grant your app access to the camera, as shown below. iOS remembers the user’s response to this alert, so subsequent uses of the capture system don’t cause it to appear again. The user can change permission settings for your app in Settings > Privacy.
To make sure your app has permission before capturing media, follow the steps below.
Configure Your App's Info.plist File
iOS requires that your app provide static messages to display to the user when the system asks for camera or microphone permission:
If your app uses device cameras, include the NSCameraUsageDescription key in your app’s Info.plist file.
If your app uses device microphones, include the NSMicrophoneUsageDescription key in your app’s Info.plist file.
For each key, provide a message that explains to the user why your app needs to capture media, so that the user can feel confident granting permission to your app.
Verify and Request Authorization for Capture
Always test the
authorization method before setting up a capture session. If the user has not yet granted or denied capture permission, the authorization status is
AVAuthorization. In this case, use the
request method to tell iOS to prompt the user:
request method is asynchronous: Your app continues running while iOS shows the permission alert. When the user responds, the system calls your completion handler. If the completion handler’s success parameter is true, you can proceed to set up and start a capture session.
Request Authorization Before Saving Captured Media
After capturing photos or video, you may want to save them into the user’s Photos library. Accessing the Photos library also requires user permission (separate from camera and microphone permission). How and when you request permission depends on which features you use for saving media:
For most photo and video capture workflows (including Live Photos and RAW format capture), use the
PHAssetclasses. These classes require read/write access to the Photos library, so you must use the use the NSPhotoLibraryUsageDescription key in your Info.plist to provide a message to the user when asking for access. For details, see Saving Captured Photos.
If your app needs only to save movie files to the Photos library, the
UISavefunction provides a simpler alternative to
Video At Path To Saved Photos Album(_: _: _: _:)
PHPhoto. This function requires only write access to the library, so use the NSPhotoLibraryAddUsageDescription key in your Info.plist to provide a message to the user when asking for permission to save to the Photos library.