tags:

views:

46

answers:

1

Hi,

I would like to know if it exists a way to check if device camera supports auto-focus ?

The only solution I found is to check device name in order to know if it supports auto-focus or not. But I did not like it because it did not work for future device.

Regards, Quentin

+2  A: 

Using the new AVFoundation APIs in iOS 4.0, you can check this by querying the AVCaptureDevice instance for the camera using its -isFocusModeSupported: method. The focus modes include AVCaptureFocusModeLocked, AVCaptureFocusModeAutoFocus, and AVCaptureFocusModeContinuousAutoFocus.

Brad Larson
Thank you, I was looking in the wrong direction (UIPickerView...).Regards,
Quentin
I can't compile code using this targeting the simulator. What's the idiom for such situations? (Or should I be able to compile it for the simulator?)
PEZ
@PEZ - I would think that you could compile this for the Simulator (perhaps you're running into [this issue](http://stackoverflow.com/questions/3677879/strange-issue-after-upgrading-to-ios-4-1-sdk)). However, you will not have access to any camera capabilities on the Simulator. You need a device for that.
Brad Larson
Thanks, Brad. Unfortunately I seem to have some other issue... When compiling for the simulator I get a an error saying that AVCaptureFocusModeAutoFocus is not declared. It's regardless if I use GCC 4.2 or LLVM and regardless if I try to set those flags in Get Info or in the .pch.
PEZ
@PEZ - Yes, I just tried and it appears that many of the new AVFoundation classes and values are not defined when building for the Simulator on 4.1. This could be an SDK issue, like the above-linked compiler settings, or they might just figure that these items are useless in the Simulator. Either way, it looks like you're stuck building for the device if you want to use this.
Brad Larson
Thanks, strangely it feels good knowing I'm stuck =) What I now did was to compile that code conditionally, which works. As it happens I'm using the ZBar library which uses the Photo Library as a camera simulation on the simulator. Pretty smart!
PEZ