Set front-facing camera in iPhone SDK

13,055

Solution 1

It's right there in the documentation:

picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;

Of course, you'll need to check first if the front camera is actually available. It's also only available starting with iOS 4.0.

Solution 2

Try this method of UIImagePickerController:

 + (BOOL)isCameraDeviceAvailable:(UIImagePickerControllerCameraDevice)cameraDevice

This is a class method and UIImagePickerControllerCameraDevice can take two values:

  - UIImagePickerControllerCameraDeviceRear
  - UIImagePickerControllerCameraDeviceFront
  Example code:

        if([UIImagePickerController isCameraDeviceAvailable: UIImagePickerControllerCameraDeviceFront ])
        {
        // do something
        }
Share:
13,055
Olav
Author by

Olav

Software developer, specializing in C++ and .NET

Updated on June 16, 2022

Comments

  • Olav
    Olav almost 2 years

    I would like to have my app open the camera (presently UIImagePickerController ) front-facing if available. (Iphone SDK).

    How can I do that?

  • Olav
    Olav over 13 years
    It seems when i set XCode SDK to IOS4 it compile, and it doesn't crash on a device without front camera. It seems the executable can also run on a device where IOS < 4, but I haven't tested all combinations.
  • Olav
    Olav over 13 years
    I now get:The Info.plist for application at....specifies a minimum OS version of 4.1, which is too high to be installed on .......
  • Olav
    Olav over 13 years
    This is when trying to run on a device where (version <4) after I had to upgrade the SDK to 4.1 because my phone with front-camera were 4.1
  • rohan-patel
    rohan-patel over 9 years
    Came across many other answers on SO and all of them suggested using AVFoundation.