4
votes

iOS 7 using UIImagePickerController to take picture twice, at second time will show a static image covered the camera, how to reset the camera.

I'm try to take picture one by one, and keep take 5 pictures.

It works on iOS6.

on iOS7, it works fine at the first time, but when it take picture at second time, it will show a static dark image on screen, how to clear or reset it, although take picture works, but user can't see what will capture with camera.

bool fistTimeToShow = YES;

-(void) viewDidAppear:(BOOL)animated{
    if (fistTimeToShow) {
        fistTimeToShow = NO;

        self.imagePickerController = nil;

        [self tackImage];
    }
}

-(void)tackImage{
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

        self.imagePickerController = [[UIImagePickerController alloc]init];
        self.imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
        self.imagePickerController.showsCameraControls = YES;
        self.imagePickerController.delegate = self;

        [self presentViewController:self.imagePickerController animated:NO completion:nil];
    }
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    NSLog(@"====== imagePickerController:didFinishPickingMediaWithInfo ======");
    [self.imagePickerController dismissViewControllerAnimated:NO completion:nil];

    //...deal with the image capture...

    self.imagePickerController = nil;

    [self tackImage];
}

Update

I change the dismiss function to put the [self tackImage]; in block. And now it always show the fist image took.

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    NSLog(@"====== imagePicker: didFinish ======");

    self.imagePickerController = nil;

    [self dismissViewControllerAnimated:NO completion: ^{
        [self tackImage];
    }];
}

I'm trying to find a way to clear the image. But I don't know where the image saved yet.

Update2

use

[self performSelector:@selector(presentCameraView) withObject:nil afterDelay:1.0f];

and function

-(void)presentCameraView{
    [self presentViewController:self.imagePickerController animated:NO completion:nil];
}

to replace. [self presentViewController:self.imagePickerController animated:NO completion:nil]; it works on my device anyway, but I don't even know why.

Update3

I have set the userInteractionEnabled to NO when Delay:1.0f to avoid other problems, and may be also need set the navigationBar and tabBar for specifically use.

1
the black camera issue is pretty common, i have a question regarding it also.. if you get to a conclussion, please can you tell me, will do the same stackoverflow.com/questions/19081701/…Heavy_Bullets
@Heavy_Bullets yes, I sent a bug report to apple, and wait for feedback. Any result will let you know.JerryZhou
I did too, but they ask me for a example project... i can't reproduce the issue (if i could, it would not be an issue), if anyone has an example, let me knowHeavy_Bullets
@Heavy_Bullets, I have create a simple demo app which can reproduce my problem, and attach to bug report. I just build it with one develop profile, not sure if it right or not. Just waiting response from apple.JerryZhou

1 Answers

0
votes

I had exactly the same issue under iOS 7 using Xamarin.iOS.

What has helped, is adding GC.Collect() in didFinishPickingMediaWithInfo method. In C# GC.Collect() "cleans up" the memory from unused/disposed objects.

For sure, there's no direct equivalent for that in Obj-C, but that may shed some light on your problem also (it could be memory-related).