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

时间:2011-09-19 09:09:01

标签: ios4 camera

我在申请中使用相机。

我想在3秒后自动拍照。 代码工作绝对可以接受一个案例..

如果应用程序进入后台,而摄像机勾选正在通过任何方式进行,例如,如果呼叫介于中间或用户按下主页键...然后当应用程序恢复时它不会继续摄像机勾选并在控制台中给出这个警告

UIImagePickerController:忽略拍照请求;相机还没准备好。

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

2 个答案:

答案 0 :(得分:0)

我们可以使用这些app委托功能

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

答案 1 :(得分: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;
}