Skip to content

Commit

Permalink
ios plugin refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
parveshneedhoo committed Mar 22, 2024
1 parent 8c1042f commit a2e45c5
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions src/ios/CameraSessionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,13 @@ - (void)switchToUltraWideCamera:(NSString*)cameraMode completion:(void (^)(BOOL
}

dispatch_async(self.sessionQueue, ^{
BOOL cameraSwitched = FALSE;
if (@available(iOS 13.0, *)) {
AVCaptureDevice *ultraWideCamera;
if([cameraMode isEqualToString:@"default"]) {
ultraWideCamera = [self cameraWithPosition:self.defaultCamera captureDeviceType:AVCaptureDeviceTypeBuiltInWideAngleCamera];
} else {
if([cameraMode isEqualToString:@"wide-angle"]) {
ultraWideCamera = [self cameraWithPosition:self.defaultCamera captureDeviceType:AVCaptureDeviceTypeBuiltInUltraWideCamera];
} else {
ultraWideCamera = [self cameraWithPosition:self.defaultCamera captureDeviceType:AVCaptureDeviceTypeBuiltInWideAngleCamera];
}
if (ultraWideCamera) {
// Remove the current input
Expand All @@ -210,33 +211,21 @@ - (void)switchToUltraWideCamera:(NSString*)cameraMode completion:(void (^)(BOOL
orientation = [self getCurrentOrientation];
});
[self updateOrientation:orientation];
if (completion) {
completion(YES);
}
cameraSwitched = TRUE;
} else {
NSLog(@"Failed to add ultra-wide input to session");
if (completion) {
completion(NO);
}
}
} else {
NSLog(@"Error creating ultra-wide device input: %@", error.localizedDescription);
if (completion) {
completion(NO);
}
}
} else {
NSLog(@"Ultra-wide camera not found");
if (completion) {
completion(NO);
}
}
} else {
// Fallback on earlier versions
if (completion) {
completion(NO);
}
}

completion ? completion(cameraSwitched): NULL;
});
}

Expand Down

0 comments on commit a2e45c5

Please sign in to comment.