Skip to content

Commit 1ecef00

Browse files
dov11sibelius
authored andcommitted
check if face or text detector libraries are included independently (react-native-camera#1863)
1 parent 20aed99 commit 1ecef00

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

ios/RN/RNCamera.m

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -341,27 +341,33 @@ - (void)updatePictureSize
341341
[self updateSessionPreset:self.pictureSize];
342342
}
343343

344-
#if __has_include(<GoogleMobileVision/GoogleMobileVision.h>)
345344
- (void)updateFaceDetecting:(id)faceDetecting
346345
{
347-
[_faceDetectorManager setIsEnabled:faceDetecting];
346+
#if __has_include("RNFaceDetectorManager.h")
347+
[_faceDetectorManager setIsEnabled:faceDetecting];
348+
#endif
348349
}
349350

350351
- (void)updateFaceDetectionMode:(id)requestedMode
351352
{
352-
[_faceDetectorManager setMode:requestedMode];
353+
#if __has_include("RNFaceDetectorManager.h")
354+
[_faceDetectorManager setMode:requestedMode];
355+
#endif
353356
}
354357

355358
- (void)updateFaceDetectionLandmarks:(id)requestedLandmarks
356359
{
357-
[_faceDetectorManager setLandmarksDetected:requestedLandmarks];
360+
#if __has_include("RNFaceDetectorManager.h")
361+
[_faceDetectorManager setLandmarksDetected:requestedLandmarks];
362+
#endif
358363
}
359364

360365
- (void)updateFaceDetectionClassifications:(id)requestedClassifications
361366
{
362-
[_faceDetectorManager setClassificationsDetected:requestedClassifications];
367+
#if __has_include("RNFaceDetectorManager.h")
368+
[_faceDetectorManager setClassificationsDetected:requestedClassifications];
369+
#endif
363370
}
364-
#endif
365371

366372

367373
- (void)takePictureWithOrientation:(NSDictionary *)options resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject{
@@ -485,8 +491,10 @@ - (void)record:(NSDictionary *)options resolve:(RCTPromiseResolveBlock)resolve r
485491
// At the time of writing AVCaptureMovieFileOutput and AVCaptureVideoDataOutput (> GMVDataOutput)
486492
// cannot coexist on the same AVSession (see: https://stackoverflow.com/a/4986032/1123156).
487493
// We stop face detection here and restart it in when AVCaptureMovieFileOutput finishes recording.
488-
#if __has_include(<GoogleMobileVision/GoogleMobileVision.h>)
494+
#if __has_include("RNFaceDetectorManager.h")
489495
[_faceDetectorManager stopFaceDetection];
496+
#endif
497+
#if __has_include("TextDetectorManager.h")
490498
[self stopTextRecognition];
491499
#endif
492500
[self setupMovieFileCapture];
@@ -597,11 +605,10 @@ - (void)startSession
597605
self.stillImageOutput = stillImageOutput;
598606
}
599607

600-
#if __has_include(<GoogleMobileVision/GoogleMobileVision.h>)
608+
#if __has_include("RNFaceDetectorManager.h")
601609
[_faceDetectorManager maybeStartFaceDetectionOnSession:_session withPreviewLayer:_previewLayer];
602-
if ([self.textDetector isRealDetector]) {
603-
[self setupOrDisableTextDetector];
604-
}
610+
#elif __has_include("TextDetectorManager.h")
611+
[self setupOrDisableTextDetector];
605612
#else
606613
// If AVCaptureVideoDataOutput is not required because of Google Vision
607614
// (see comment in -record), we go ahead and add the AVCaptureMovieFileOutput
@@ -634,7 +641,7 @@ - (void)stopSession
634641
return;
635642
#endif
636643
dispatch_async(self.sessionQueue, ^{
637-
#if __has_include(<GoogleMobileVision/GoogleMobileVision.h>)
644+
#if __has_include("RNFaceDetectorManager.h")
638645
[_faceDetectorManager stopFaceDetection];
639646
#endif
640647
if ([self.textDetector isRealDetector]) {
@@ -930,7 +937,7 @@ - (void)cleanupCamera {
930937
self.videoRecordedReject = nil;
931938
self.videoCodecType = nil;
932939

933-
#if __has_include(<GoogleMobileVision/GoogleMobileVision.h>)
940+
#if __has_include("RNFaceDetectorManager.h")
934941
[self cleanupMovieFileCapture];
935942

936943
// If face detection has been running prior to recording to file
@@ -999,7 +1006,7 @@ - (id)createFaceDetectorManager
9991006
Class faceDetectorManagerClass = NSClassFromString(@"RNFaceDetectorManager");
10001007
Class faceDetectorManagerStubClass = NSClassFromString(@"RNFaceDetectorManagerStub");
10011008

1002-
#if __has_include(<GoogleMobileVision/GoogleMobileVision.h>)
1009+
#if __has_include("RNFaceDetectorManager.h")
10031010
if (faceDetectorManagerClass) {
10041011
return [[faceDetectorManagerClass alloc] initWithSessionQueue:_sessionQueue delegate:self];
10051012
} else if (faceDetectorManagerStubClass) {
@@ -1028,7 +1035,7 @@ -(id)createTextDetector
10281035
Class textDetectorManagerStubClass =
10291036
NSClassFromString(@"TextDetectorManagerStub");
10301037

1031-
#if __has_include(<GoogleMobileVision/GoogleMobileVision.h>)
1038+
#if __has_include("TextDetectorManager.h")
10321039
if (textDetectorManagerClass) {
10331040
return [[textDetectorManagerClass alloc] init];
10341041
} else if (textDetectorManagerStubClass) {

0 commit comments

Comments
 (0)