Apple Dog
Apple Dog

Reputation: 35

(AVCaptureDevice) Why can't I get my camera device

I wrote the following code, but I can't get my camera device. It always crash

guard let captureDevice = AVCaptureDevice.default(.builtInDualCamera, for: .video, position: .back) else {
  fatalError()
}

After I change to the following code, it's work!

guard let captureDevice = AVCaptureDevice.default(for: AVMediaType.video) else {
   fatalError()
}

Could anyone tell me why? thank you!!

Upvotes: 2

Views: 664

Answers (1)

Hitesh Surani
Hitesh Surani

Reputation: 13537

Code 1 :

guard let captureDevice = AVCaptureDevice.default(.builtInDualCamera, for: .video, position: .back) else {
  fatalError()
}

Here you have used a keyword builtInDualCamera which is not available in every Apple device. That's why your application got crashed.

enter image description here

Code 2:

guard let captureDevice = AVCaptureDevice.default(for: AVMediaType.video) else {
   fatalError()
}

Above code just check that your device having video capturing capacity or not. I think all devices are having this functionality that's why it is working.

Upvotes: 2

Related Questions