Reputation: 1784
On all iOS 8 devices I'm facing a new issue when I'm using the UIImagePickerController (on iOS 7 it's working fine). The first shot works as expected. When I try to to take another photo the UIImagePickerController appears but shows a black screen.
All the controls such as switch camera, cancel and take photo button are available and working. If I try to make the second photo and touch the button I get a correct preview of the taken photo. If I save that photo and try to make another one all behaves as expected. Only the fourth photo has the same issue again. And so on...
This is my code:
public void ButtonCameraClicked(object sender, EventArgs eventArgs)
{
_imagePickerDelegate = new ImagePickerControllerDelegate(this);
_imagePicker = new UIImagePickerController();
_imagePicker.ImagePickerControllerDelegate = _imagePickerDelegate;
if (UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.Camera))
_imagePicker.SourceType = UIImagePickerControllerSourceType.Camera;
else
_imagePicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary;
PresentViewController(_imagePicker, true, null);
}
public override void FinishedPickingMedia(UIImagePickerController picker, NSDictionary info)
{
BTProgressHUD.Show("Bild wird gespeichert...");
var image = (UIImage)info.ObjectForKey(new NSString("UIImagePickerControllerOriginalImage"));
image.SaveToCustomPhotosAlbum(info[UIImagePickerController.MediaMetadata] as NSDictionary, _controller.AlbumName, _controller.MediaSaved);
picker.DismissViewController(true, null);
}
I've already googled a lot an tried the following things without any success
Initializing just once
if (_imagePicker == null)
{
_imagePickerDelegate = new ImagePickerControllerDelegate(this);
_imagePicker = new UIImagePickerController();
_imagePicker.ImagePickerControllerDelegate = _imagePickerDelegate;
}
Or using a completion block
PresentViewController(_imagePicker, true, () => { });
PresentViewController(_imagePicker, true, () => { Thread.Sleep(300); });
Or synchronising to main thread
InvokeOnMainThread(() => { ... });`
`NSOperationQueue.MainQueue.AddOperation(() => { ... });
The whole code file is available on: https://gist.github.com/anonymous/83a855d44d697235849b
Upvotes: 2
Views: 1545
Reputation: 1453
I tried everything you tried and then decided to go a different route. The Xamarin.Mobile component on the component store not only provides a cross platform implementation of camera but in my testing was not subject to the same iOS 7+ black preview screen problem.
Sample Usage from https://components.xamarin.com/gettingstarted/xamarin.mobile
using Xamarin.Media;
using System.Threading;
using System.Threading.Tasks;
//...
var picker = new MediaPicker();
MediaPickerController controller = picker.GetTakePhotoUI (new StoreCameraMediaOptions {
Name = "test.jpg",
Directory = "MediaPickerSample"
});
// On iPad, you'll use UIPopoverController to present the controller
PresentViewController (controller, true, null);
controller.GetResultAsync().ContinueWith (t => {
// Dismiss the UI yourself
controller.DismissViewController (true, () => {
//might want to add if(t.Result.Status = task.enumstatus.rantocompletion)
//or camera cancels will throw exceptions
MediaFile file = t.Result;
});
}, TaskScheduler.FromCurrentSynchronizationContext());
Upvotes: 0