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
}
Comments
-
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 over 13 yearsIt 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 over 13 yearsI 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 over 13 yearsThis 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 over 9 yearsCame across many other answers on SO and all of them suggested using
AVFoundation
.