开发者

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.


You can access the front facing camera like:

picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;

Check out the UIImagePickerController Class Reference


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


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.


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];


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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜