Created
January 24, 2019 17:37
-
-
Save xhruso00/d5b1a4a90d579f1e1b05d1307b2a1522 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <AVFoundation/AVFoundation.h> | |
@interface AVCaptureDevice(Additions) | |
+ (NSArray<AVCaptureDevice *>*)inputCameraDevices; | |
- (BOOL)isBuiltIn; | |
- (BOOL)hasVideoMedia; | |
- (BOOL)canOpenCamera; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "AVCaptureDevice+Additions.h" | |
@implementation AVCaptureDevice(Additions) | |
+ (NSArray<AVCaptureDevice *>*)inputCameraDevices | |
{ | |
NSArray<AVCaptureDevice *>* videoDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]; | |
NSArray<AVCaptureDevice *>* muxedDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeMuxed]; | |
return [videoDevices arrayByAddingObjectsFromArray:muxedDevices]; | |
} | |
- (BOOL)isBuiltIn | |
{ | |
return [self transportType] == 'bltn' ? YES : NO; | |
} | |
- (BOOL)hasVideoMedia | |
{ | |
if ([self hasMediaType:AVMediaTypeMuxed] == NO) { | |
return [self hasMediaType:AVMediaTypeVideo]; | |
} | |
return YES; | |
} | |
- (BOOL)canOpenCamera | |
{ | |
BOOL canOpenCamera = NO; | |
if ([self hasVideoMedia] && [self isConnected]) { | |
canOpenCamera = [self isInUseByAnotherApplication] == NO ? YES : NO; | |
} | |
if ([self isBuiltIn]) { | |
canOpenCamera = [[NSUserDefaults standardUserDefaults] boolForKey:@"DisableInternalCamera"] == YES ? NO : YES; | |
} | |
return canOpenCamera; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment