Search code examples
ioscamerarotationxamarinmvvmcross

Preventing the camera to rotate in iPad app using MvvmCross PictureChooser


I'm using Xamarin with MvvmCross to create an iPad application. In this application I use the PictureChooser plugin to take a picture with the camera. This all occurs in the way that can be seen in the related youtube video.

The code to accomplish this is fairly simple and can be found below. However when testing this on the actual device, the camera might be rotated.

private readonly IMvxPictureChooserTask _pictureChooserTask;

public CameraViewModel(IMvxPictureChooserTask pictureChooserTask)
{
    _pictureChooserTask = pictureChooserTask;
}

private IMvxPictureChooserTask PictureChooserTask { get { return _pictureChooserTask; } }

private void TakePicture()
{
    PictureChooserTask.TakePicture(400, 95,
        async (stream) =>
        {
            using (var memoryStream = new MemoryStream())
            {
                stream.CopyTo(memoryStream);
                var imageBytes = memoryStream.ToArray();

                if (imageBytes == null)
                    return;

                filePath = ProcessImage(imageBytes, FileName);
            }
        },
        () =>
        {
            /* no action - we don't do cancellation */
        }
    );
}

This will lead to unwanted behavior. The camera should remain steady and be prevented in rotating within the App. I have been trying some stuff out, like preventing the app from rotating in the override bool ShouldAutorotate method while in camera mode, but unfortunately without any results.

Is there any setting that I forgot to set on the PictureChooser, or is the override method the item where I should perform some magic?

Thanks in advance.


Solution

  • Answer to this question has been raised in the comments of the question by user3455363, many thanks for this! Eventually it seemed to be a bug in iOS 8. The iOS 8.1 upgrade fixed this issue in my App!