Contents

setPrimaryConstituentDeviceSwitchingBehavior(_:restrictedSwitchingBehaviorConditions:)

Sets the switching behavior of the primary constituent device.

Declaration

func setPrimaryConstituentDeviceSwitchingBehavior(_ switchingBehavior: AVCaptureDevice.PrimaryConstituentDeviceSwitchingBehavior, restrictedSwitchingBehaviorConditions: AVCaptureDevice.PrimaryConstituentDeviceRestrictedSwitchingBehaviorConditions)

Parameters

  • switchingBehavior:

    The switching behavior to set on the device.

  • restrictedSwitchingBehaviorConditions:

    Sets the conditions during which the system restricts switching cameras.

    Setting the switching behavior to a value other than Restricted requires that you set this argument to an empty option set.

Discussion

Use this method to configure the camera switching behavior of a capture device. Before calling it, determine if a device supports configuring its device switching behavior by querying the device’s activePrimaryConstituentDeviceSwitchingBehavior property. If the value equals .unsupported, attempting to configure its switching behavior results in an error.

// Exit early if the device doesn't support configuring switching behavior.
guard captureDevice.activePrimaryConstituentDeviceSwitchingBehavior != .unsupported else { return }
captureDevice.setPrimaryConstituentDeviceSwitchingBehavior(.auto, restrictedSwitchingBehaviorConditions: [])

When recording using an instance of AVCaptureMovieFileOutput, you may override the switching behavior by calling the movie file output’s setPrimaryConstituentDeviceSwitchingBehaviorForRecording(_:restrictedSwitchingBehaviorConditions:) method.

See Also

Restricting camera switching