2011-09-19 13 views
5

Estoy usando la cámara en mi aplicación.UIImagePickerController: ignorando la solicitud para tomar una foto; la cámara aún no está lista

Quiero tomar una foto después de 3 segundos automáticamente. El código está funcionando absolutamente bien, acepte para un caso ...

Si la aplicación entra en el fondo mientras la señal de la cámara se ejecuta de alguna manera, como si la llamada entra o el usuario presiona la tecla de inicio ... entonces cuando la aplicación se reanuda no continúa el tic de la cámara y en la consola da esta advertencia

UIImagePickerController: ignorando la solicitud para tomar una fotografía; la cámara aún no está lista.

Quiero reiniciar la cámara cuando tal cosa ocurra ¿qué debo hacer?

Respuesta

0

podemos utilizar estas funciones de delegado aplicación

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

lo que hice para resolver este problema:

- (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; 
} 
Cuestiones relacionadas