Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
392 views
in Technique[技术] by (71.8m points)

uiimagepickercontroller - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...