UIImagePickerController:忽略拍照请求;相机尚未准备好

发布于 2024-12-05 10:02:27 字数 238 浏览 0 评论 0原文

我在我的应用程序中使用相机。

我想3秒后自动拍照。 对于一种情况,代码工作绝对正常。

如果应用程序在相机滴答声以任何方式进行时进入后台,例如如果中间有呼叫或用户按主页键...那么当应用程序恢复时它不会继续相机勾选,并在控制台中给出此警告

UIImagePickerController:忽略拍照请求;相机尚未准备好。

发生这种情况时我想重新启动相机 我应该怎么办?

I am using camera in my application.

I want to take picture after 3 seconds automatically.
The code is working absolutely fine accept for one case..

If application goes into background while camera tick is going on by any ways like if call comes in-between or user presses home key...then when the application is resumed it does not continue the camera tick and in console it gives this warning

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

I want to restart the camera when such thing happens
what should i do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

GRAY°灰色天空 2024-12-12 10:02:27

我们可以使用这些应用程序委托函数

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

we can use these app delegate functions

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
千と千尋 2024-12-12 10:02:27

我为解决这个问题做了什么:

- (void)viewDidAppear:(BOOL)animated {
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(cameraIsReady:)
                                                 name:AVCaptureSessionDidStartRunningNotification object:nil];

    self.ready = NO;
    if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        // There is not a camera on this device, so don't show the camera button.
        [self showImagePickerForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
    } else {
        [self showImagePickerForSourceType:UIImagePickerControllerSourceTypeCamera];
    }
}

- (void)cameraIsReady:(NSNotification *)notification {
    self.ready = YES;
}

- (IBAction)takePhoto:(id)sender {
    if (self.ready) {
        [self.imagePickerController takePicture];
    }
    self.ready = NO;
}

What i did to solve this issue:

- (void)viewDidAppear:(BOOL)animated {
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(cameraIsReady:)
                                                 name:AVCaptureSessionDidStartRunningNotification object:nil];

    self.ready = NO;
    if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        // There is not a camera on this device, so don't show the camera button.
        [self showImagePickerForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
    } else {
        [self showImagePickerForSourceType:UIImagePickerControllerSourceTypeCamera];
    }
}

- (void)cameraIsReady:(NSNotification *)notification {
    self.ready = YES;
}

- (IBAction)takePhoto:(id)sender {
    if (self.ready) {
        [self.imagePickerController takePicture];
    }
    self.ready = NO;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文