1

Hello I'm working in an app with camera.

I can open and use the camera correctly. But I find a bug:

When I open the camera, flips camera, again flips camera and press cancel. Do it a few times ( 3 - 5 ) . Open again the camera and I have a black freeze screen for a few seconds and if you take a picture see the image but the screen continue in black. After a few seconds the camera appears again and you can continue with the normal behavior. But I cant find a solution to this.

I searched a lot in internet and find some answers but nothing solve my problem.

Here a similar problem but the solution didnt work for me:

Also I use DejalBezelActivityView to create a spinner area with a label DejalBezelActivityView

Any idea?

I have my .h declaration:

@property (nonatomic, strong) UIImagePickerController* picker;

- (void) takePhoto: (id)vc;
- (void) selectPhoto: (id)vc;

And my .mm code:

@synthesize picker = _picker;

- (id) init{
self = [super init];

if (self){
    self.picker = [[UIImagePickerController alloc] init];

}
return self;
}



- (void)takePhoto:(id)vc{
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
    [VC_Camera showAlert];
    return;
}

[self init];
self.picker.delegate = self;
self.picker.allowsEditing = YES;
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;

[[VC_Camera getMainWindow] presentViewController:self.picker animated:YES completion:NULL];
}

- (void)selectPhoto:(id)vc{
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){
    [VC_Camera showAlert];
    return;
}

[self init];    
self.picker.delegate = self;
self.picker.allowsEditing = YES;
self.picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

[[VC_Camera getMainWindow] presentViewController:self.picker animated:YES completion:NULL];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

self.picker = picker;

DejalActivityView * _activityView = [DejalBezelActivityView activityViewForView:[[UIApplication sharedApplication] keyWindow]  withLabel:@"Loading"];

  [self performSelector:@selector(cancelAfterDelay:) withObject:@{@"DejalAV":_activityView} afterDelay:1.0];

}


- (void) cancelAfterDelay:(NSDictionary*) dict
{

DejalActivityView* _activityView = [dict objectForKey:@"DejalAV"];

[DejalBezelActivityView removeViewAnimated:YES];

[self.picker dismissViewControllerAnimated:YES completion:nil];
}

Thanks :D

[UPDATE]

I try to use the UIImagePickerController as a singleton:

-(UIImagePickerController *) imagePicker{
if(!_imagePicker){
   _imagePicker = [[UIImagePickerController alloc] init];
   _imagePicker.delegate = self;
   if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
       _imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
   }
   else{
       _imagePicker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
   }  
}
return _imagePicker;
}

And the problem persist.

Community
  • 1
  • 1
dPeluChe
  • 11
  • 2

1 Answers1

0

This is a very late response, but for those still wrestling with this issue: I've noticed this seems to happen when something is either backing up the main thread, or affecting the graphics context on a separate thread. Those might be places to start looking.

jcasts
  • 1