Oliver
Oliver

Reputation: 23510

iPhone - Detecting if the iDevice has a front camera

Apple recommends not searching for hardware version, but for the specific feature in which you are interested.

So how may I detect if there is a front camera on the device to be able to disable some features ?

[UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera] only tells that there is a camera somewhere.

Upvotes: 22

Views: 9624

Answers (2)

vidhyagoutham
vidhyagoutham

Reputation: 39

In Swift

imagePicker.cameraDevice = UIImagePickerControllerCameraDevice.Front

Upvotes: 2

quaertym
quaertym

Reputation: 3961

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
}

Note that this is available for iOS 4.0 and later.

Upvotes: 45

Related Questions