Albert Renshaw
Albert Renshaw

Reputation: 17892

UIImagePickerController - How do I access the front facing camera by default?

I am bringing up the camera with the following code from my ViewController:

- (void)viewDidLoad {
    self.imgPicker = [[UIImagePickerController alloc] init];
    self.imgPicker.sourceType = UIImagePickerControllerCameraDeviceFront;
    self.imgPicker.delegate = self;     
}

- (IBAction)grabCamera {
    [self presentModalViewController:self.imgPicker animated:YES];
}

How can I make it so the camera by default uses the front camera of the iPhone4 and not the back camera?

Upvotes: 38

Views: 15429

Answers (1)

MattyG
MattyG

Reputation: 8497

UIImagePickerControllerCameraDeviceFront is not a valid enum for the sourceType property. The sourceType property defines whether you're using the camera or the photo library. You need to set the cameraDevice property instead.

Objective-C

self.imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imgPicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;

Swift 2

imgPicker.sourceType = .Camera
imgPicker.cameraDevice = .Front

Swift 3

imgPicker.sourceType = .camera
imgPicker.cameraDevice = .front

Upvotes: 81

Related Questions