开发者

How to detect camera existence with `AVFoundation`?

开发者 https://www.devze.com 2023-02-18 18:03 出处:网络
Now iOS devices has 0~2 camera开发者_Go百科s. How to detect them?You iterate through the video devices...

Now iOS devices has 0~2 camera开发者_Go百科s. How to detect them?


You iterate through the video devices...

NSArray *videoDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
AVCaptureDevice *captureDevice = nil;

for (AVCaptureDevice *device in videoDevices) {
    if (device.position == AVCaptureDevicePositionFront) {
        //FRONT-FACING CAMERA EXISTS
    }
}

Of course you could also do this a bit quicker with a predicate, but i'll leave that for you to work out ;).... (HINT: use the filteredArrayUsingPredicate: method on the devicesWithMediaType:)

0

精彩评论

暂无评论...
验证码 换一张
取 消