2011-05-02 80 views
4

我有一个使用下面的宏的应用:iPad 2的摄像头,支持检测

#define IS_IPAD ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] && [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)

这工作对我非常好。

但是,我使用它来关闭在应用程序中拍摄照片的选项。

如何检测相机选项是否可用,而不管设备是否可用?

回答

12

[的UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];

这应该工作

+0

甜蜜的感谢!看起来很干净。 – Mark 2011-05-02 23:25:33

2

请参阅How to Detect Camera Existence with AVFoundation

NSArray *videoDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]; 
AVCaptureDevice *captureDevice = nil; 

if ([videoDevices count] > 0) // This device has one or more cameras 
.... 
+0

感谢胡里奥,你会这有超过约书亚的答案吗? – Mark 2011-05-02 23:25:57

+0

Joshua的片段比较简单,除非你需要每个单独相机的扩展信息,他的答案应该足够了。 – 2011-05-02 23:57:47

+0

我也会在3.x上工作,但这几天不是很重要 – 2011-05-03 00:00:39