Tapy
Tapy

Reputation: 1054

Accessing the front facing camera. iPhone/iPod 4

Hey I was wondering how I can access the front facing camera. Maybe there's some guide for it? But I don't want all buttons etc. I just want to access the from facing camera, I don't ant the button to take a photo or anything like that.

Upvotes: 5

Views: 8019

Answers (5)

RamaKrishna Chunduri
RamaKrishna Chunduri

Reputation: 1130

Well, what "Khushbu Shah" said is right. however actually the isCameraDeviceAvailable is available only ios 4 and above. Just to ensure that you opened the front camera only if it is there, the right code block to be used is as follows.

UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.delegate = self;
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
    ipc.sourceType = UIImagePickerControllerSourceTypeCamera;

    if([UIImagePickerController respondsToSelector:@selector(isCameraDeviceAvailable:)])
    { //check if iphone 4 and above
        if([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront])
        {
            ipc.cameraDevice=UIImagePickerControllerCameraDeviceFront;
        }
    }
}

[ipc release];

Upvotes: 2

Khushbu Shah
Khushbu Shah

Reputation: 282

First thing you need to do is to detect if your device has got front-facing camera. For that you need to iterate through the video devices.

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
}

Upvotes: 1

WrightsCS
WrightsCS

Reputation: 50697

You can access the front facing camera like:

picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;

Check out the UIImagePickerController Class Reference

Upvotes: 17

Clad
Clad

Reputation: 1561

You should initiate an AVCaptureSession and specify which AVCaptureDevice to use ( AVCaptureDevicePositionFront in your case).

Start looking for the AVCaptureSession documentation and you should have a better understanding of what to do.

Upvotes: 2

Henrik P. Hessel
Henrik P. Hessel

Reputation: 36617

Just set the cameraDevice property of UIImagePickerController to UIImagePickerControllerCameraDeviceFront. But you should check if the device is available.

Upvotes: 3

Related Questions