@@ -179,14 +179,39 @@ @interface CardIOVideoStream ()
179
179
180
180
@implementation CardIOVideoStream
181
181
182
+ - (AVCaptureDevice *)cameraWithPosition : (AVCaptureDevicePosition)position {
183
+ return [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes: @[ AVCaptureDeviceTypeBuiltInWideAngleCamera ]
184
+ mediaType: AVMediaTypeVideo
185
+ position: position].devices .firstObject ;
186
+ }
187
+
182
188
- (id )init {
183
189
if ((self = [super init ])) {
184
190
_interfaceOrientation = (UIInterfaceOrientation)UIDeviceOrientationUnknown;
185
191
_scanner = [[CardIOCardScanner alloc ] init ];
186
192
_cameraConfigurationSemaphore = dispatch_semaphore_create (1 ); // parameter of `1` implies "allow access to only one thread at a time"
187
193
#if USE_CAMERA
188
194
_captureSession = [[AVCaptureSession alloc ] init ];
189
- _camera = [AVCaptureDevice defaultDeviceWithMediaType: AVMediaTypeVideo];
195
+ _camera = [self cameraWithPosition: AVCaptureDevicePositionUnspecified];
196
+ _previewLayer = [AVCaptureVideoPreviewLayer layerWithSession: self .captureSession];
197
+ dmz = dmz_context_create ();
198
+ #elif SIMULATE_CAMERA
199
+ _previewLayer = [SimulatedCameraLayer layer ];
200
+ #endif
201
+ }
202
+ return self;
203
+ }
204
+
205
+
206
+ - (id )initWithCameraPosition : (AVCaptureDevicePosition )cameraPosition {
207
+ if ((self = [super init ])) {
208
+
209
+ _interfaceOrientation = (UIInterfaceOrientation)UIDeviceOrientationUnknown;
210
+ _scanner = [[CardIOCardScanner alloc ] init ];
211
+ _cameraConfigurationSemaphore = dispatch_semaphore_create (1 ); // parameter of `1` implies "allow access to only one thread at a time"
212
+ #if USE_CAMERA
213
+ _captureSession = [[AVCaptureSession alloc ] init ];
214
+ _camera = [self cameraWithPosition: cameraPosition];
190
215
_previewLayer = [AVCaptureVideoPreviewLayer layerWithSession: self .captureSession];
191
216
dmz = dmz_context_create ();
192
217
#elif SIMULATE_CAMERA
0 commit comments