Hi. I can't figure out how to access the camera flash on the iPhone 4 for my app. Is anyone able to figure this out? I looked through the developer documentation and still can't figure it out. Thanks.
EDIT:When I try to import the <AVFoundation/AVFoundation.h, it's almost as if it doesn't detect it. For instance, I will type AVCaptureDevice in the .h file and it won't recognize it and give me an error. It detects that I've imported some classes (such as the ones that were in 3.0) but not the ones that are new to 4.0 (which one I need).
Last edited by Whitehk; 06-29-2010 at 02:33 PM.
Reason: New Problem arised
HAve you tried the AVCaptureDevice class? I don't have an iPhone4, so I can't try it, but it looks like the way to go.
Yeah. That's the one I was looking at. I'm kind of a newbie and I'm trying to learn how to use the developer documentation. I just couldn't figure out how to implement it.
Since you are doing something that's not standard, there's not going to be sample code. So your choice is either try it yourself, or wait until someone else does and posts it. (If you can wait 3-4 weeks, that's when I get my iPhone 4).
If I were you, I would play with the devices array, taking each element and setting flashMode until one of them turned on the flash. IT might look something like this:
Code:
NSArray *devices = [AVCaptureDevice devices];
for (AVCaptureDevice *device in devices) {
device.flashMode = AVCaptureFlashModeOn;
}
Keep in mind, I'm guessing since I don't have the hardware, but see if that gets you started.
Since you are doing something that's not standard, there's not going to be sample code. So your choice is either try it yourself, or wait until someone else does and posts it. (If you can wait 3-4 weeks, that's when I get my iPhone 4).
If I were you, I would play with the devices array, taking each element and setting flashMode until one of them turned on the flash. IT might look something like this:
Code:
NSArray *devices = [AVCaptureDevice devices];
for (AVCaptureDevice *device in devices) {
device.flashMode = AVCaptureFlashModeOn;
}
Keep in mind, I'm guessing since I don't have the hardware, but see if that gets you started.
Ok. I will look at it and see if I can get it working. Thanks for your help.
I'm having a very similar problem with trying to access the AVCaptureDevice class. I've imported the AVFoundation.framework into my project and also did an import statement of the AVFoundation/AVFoundation.h, but XCode just keeps saying AVCaptureDevice is undeclared. Also if I look at the header files within the framework itself, it's missing half of the 4.0 specific AVFoundation classes found within the documentation. Any ideas?
EDIT:
It wont compile when building for the sim but builds and runs on my iPhone 4. When I tap the button with this action it returns SIGBART on it. telling me
Sorry, I was talking more generally, in regards to your code, you need to run lockForConfiguration and unlockForConfiguration before and after changing device properties.
I have tried all of these suggestions and got nothing to turn on. All of the calls work without errors and the flash modes are tuned on but nothing happens.
A question which is a little out of topic; do anyone know how can I set the video encoding format as H264 when recording video using AVCaptureSession, AVCaptureInput and AVCaptureOutput?
I have tried all of these suggestions and got nothing to turn on. All of the calls work without errors and the flash modes are tuned on but nothing happens.