如何知道iPhone相机是否准备好拍照? [英] How to know if iPhone camera is ready to take picture?

查看:66
本文介绍了如何知道iPhone相机是否准备好拍照?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在相机准备就绪之前调用[camera takePicture]时,它会显示以下消息:

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]始终返回true,即使它似乎还没有准备好.

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

推荐答案

正如@djromero所说的那样,可以使用AVFoundation解决方案(但不是 代替UIImagePickerController.您只需使用AVFoundation即可收到通知).

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
}

我刚刚通过在UIImagePickerController演示文稿(我收到相机未准备好"消息)后调用takePicture并在通知回调内部调用它来进行测试,它像一种魅力一样工作.

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.

旁注:

[camera isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]始终返回Yes,因为它仅检查是否有可用的摄像头设备.实际上,Apple建议您在尝试初始化和呈现之前,必须始终检查它是否返回Yes并且您具有非nil委托(以提供通过标准接口通过dismiss选择器的方式).控制器.

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

这篇关于如何知道iPhone相机是否准备好拍照?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆