4

I have this simple code for camera View controller:

UIImagePickerController picker = new UIImagePickerController();
picker.PrefersStatusBarHidden ();
picker.SourceType = UIImagePickerControllerSourceType.Camera;
UIImagePickerControllerCameraDevice dev = picker.CameraDevice;
PresentViewController (picker, false, null);
picker.FinishedPickingMedia += (object sender, UIImagePickerMediaPickedEventArgs e) => BeginInvokeOnMainThread (delegate {DismissViewController (false, null);});

When app starts, I can capture photo normally, but when i present picker again, camera View appears but frame(image) from previous shot is shown and frozen. If i move my device around image doesn't change. In other words, I can use camera once but I can not use it twice. What I am doing wrong? On iOS6 devices it works perfectly.

Stephane Delcroix
  • 16,134
  • 5
  • 57
  • 85
milan.rancic
  • 219
  • 1
  • 8

1 Answers1

4

Making a pickerDelegate class did the trick for me. You just have to pass the current VC in the constructor so you can handle the image in your VC.

PickerDelegate

private class pickerDelegate : UIImagePickerControllerDelegate
        {
            private yourVC _vc;

            public pickerDelegate (yourVC controller) : base ()
            {
                _vc = controller;
            }

            public override void FinishedPickingImage (UIImagePickerController picker, UIImage image, NSDictionary editingInfo)
            {
               //Do something whit the image
                _vc.someButton.SetBackgroundImage (image, UIControlState.Normal);

                //Dismiss the pickerVC
                picker.DismissViewController (true, null);
            }
        }

ViewDidLoad

imagePicker = new UIImagePickerController ();

//Set the Delegate and pass the current VC
imagePicker.Delegate = new pickerDelegate (this);
Florian Schaal
  • 2,586
  • 3
  • 39
  • 59
  • 1
    Thanks. Switching from Events to the Delegate model. Fixed it for me too. Here s the link that brought me here and has some additional info: http://stackoverflow.com/a/20503817/383658 – schmidiii Dec 20 '13 at 12:12
  • HI i have the same issue. i use MvvmCross picturechooser plugin. and looking at their source code they use delegate, but event the problem is still there for my app? can you guide me? – SoftSan Feb 07 '14 at 11:03
  • Same here. Looks like to HAVE to dismiss. Can only use the camera once on iOS 9.1 – Leslie Godwin Jan 27 '16 at 11:38