UIImagePickerController: ignoring a request for a survey; the camera is not ready yet

I use the camera in my application.

I want to take a picture in 3 seconds automatically. The code works absolutely fine for one case.

If the application goes into the background while the camera’s tick continues in any way, for example, if the call comes in between or the user presses the home key ... then when the application resumes, it does not continue to tick the camera, and in the console it gives it warning

UIImagePickerController: ignoring a request for a survey; The camera is not ready yet.

I want to reboot the camera when this happens, what should I do?

+5
source share
2 answers

- (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.
}
0

:

- (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;
}
0

All Articles