Contents

requestAccess(for:completionHandler:)

Requests the user’s permission to allow the app to capture media of a particular type.

Declaration

class func requestAccess(for mediaType: AVMediaType, completionHandler handler: @escaping  @Sendable (Bool) -> Void)
class func requestAccess(for mediaType: AVMediaType) async -> Bool

Parameters

  • mediaType:

    A media type for which to check the authorization status. The supported media types are Video and Audio.

  • handler:

    A callback the system invokes with a Boolean value that indicates whether the user granted or denied access to your app.

    Return control to the main queue or Mainactor before performing user interface updates.

Mentioned in

Discussion

Capturing media requires explicit permission from the user. An app’s default authorization status is AVAuthorizationStatus.notDetermined, which means the user hasn’t yet granted it permission to capture media. The first time you create an AVCaptureDeviceInput object for a media type that requires permission, the system automatically displays an alert to request recording permission. Alternatively, call this method to prompt the user at a time of your choosing. The system saves the user’s selection so that it doesn’t have to prompt the user again. A user can change their authorization status in the Settings app.

Calling this method doesn’t block the thread while the system is prompting the user for access. However, until the grants permission, the system only vends black video frames and silent audio samples.

See Also

Authorizing device access