Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know if iPhone camera is ready to take picture?

When [camera takePicture] is called before the camera is ready, it spits out this message:

UIImagePickerController: ignoring request to take picture; camera is not yet ready.

How can I know when it is ready to take a photo?

[camera isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] always returns true, even when it's apparently not ready.

like image 922
James Skidmore Avatar asked May 20 '12 23:05

James Skidmore


People also ask

How do I test my camera on my iPhone?

To open Camera, swipe left on the iPhone Lock Screen or tap Camera on the iPhone Home Screen. Note: For your security, a green dot appears in the top-right corner of the screen when Camera is in use. See Control access to hardware features.

How do I enable my camera on my iPhone?

Step 1: Go to Settings > Privacy. Step 2: Tap on Camera to see which apps have access to it. You can allow or block apps using Camera from here.


2 Answers

As @djromero said there is a solution by using AVFoundation (but not instead of UIImagePickerController. You just use AVFoundation to get a notification back).

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(cameraIsReady:)
                                             name:AVCaptureSessionDidStartRunningNotification object:nil];

And then, once the camera is ready you got your notification:

- (void)cameraIsReady:(NSNotification *)notification
{   
    NSLog(@"Camera is ready...");
    // Whatever
}

I have just tested it by calling takePicture after UIImagePickerController presentation (where I got the 'camera is not ready' message) and right inside my notification callback, where it worked like a charm.

Side-note:

[camera isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] always returns Yes because it only checks that there is a camera device available. As a matter of fact, Apple recommends that you always must check that this returns Yes and that you have a non nil delegate (to provide a way to dismiss the picker through the standard interface) before you try to initialize and present the controller.

like image 173
Alladinian Avatar answered Oct 18 '22 16:10

Alladinian


To be honest I haven't tried it and the documentation is somewhat ambiguous, but what about [UIImagePickerController isCameraDeviceAvailable:...]?

EDIT: As I just learned, this is not the solution for your problem. Sorry, I thought it might be worth a try...

like image 39
Stefan Avatar answered Oct 18 '22 16:10

Stefan