tags:

views:

151

answers:

3

I'm writing an iOS app, and I need to be able to detect if the device has a camera. Previously, I would check if the device is an iPhone or not, since only the iPhone has a camera - but with the launch of the iPod touch 4 this is no longer a viable option. The app functions without a camera, but the presence of a camera adds functionality.

So, can anyone provide me with code that returns whether there is a camera or not?

A: 

I've never worked with the iPhone camera, so I don't know if there is a default function for taking pictures. If there is, you could use the respondsToSelector: method.

Assuming you take pictures using deviceToTakePictureNow:, it would be something like

[[UIDevice currentDevice] respondsToSelector:@selector(deviceToTakePictureNow:)]
Aloha Silver
+3  A: 

You can use +isSourceTypeAvailable: method in UIImagePickerController:

if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
   // Has camera
Vladimir
Thank you very much!
Origamiguy
+1  A: 

Yes, there is an API provided to do just that:

BOOL isCamera = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
quixoto