locked
MediaPicker TakePhotoAsync Crashing on iOS10 RRS feed

  • Question

  • User33143 posted

    I've got the following code, and it's working just fine on iOS9. But when I installed iOS10 on my iPhone it suddenly started blowing up the minute that I try to start taking a picture. Considering that our app is entirely taking pictures and submitting them, this is a serious problem. Anyone have any leads on a fix?

    try
    {
        if (_mediaPicker.IsCameraAvailable)
        {
            // Do stuff - **Gets here**
            await _mediaPicker.TakePhotoAsync(BuildMediaOptions()).ContinueWith(t => 
            {
                // More stuff - **Doesn't get here**
                EnsureInvokedOnMainThread(() => {
                // More stuff
                });
            });
        }
        else
        {
            new UIAlertView("No Camera", "There is no camera available on this device.", null, "OK", null).Show();
        }
    }
    catch (Exception ex)
    {
        // Catch stuff, print exception - **Doesn't get here**
    }
    finally
    {
        // Finalize stuff - **Or here**
    }
    

    More than just that, it's crashing without any useful debugging information being printed at all. Either in the (now useless, thanks Apple for XCode 8) device logs, or in the debug logs.

    Thursday, September 15, 2016 5:38 PM

All replies

  • User33143 posted

    Update: created an entirely new project, with just literally a button that opens up a camera, and it doesn't work.

    using System;
    
    using UIKit;
    
    using Foundation;
    using Xamarin.Media;
    
    namespace CameraTest
    {
        public partial class ViewController : UIViewController
        {
            MediaPicker _mediaPicker;
    
            protected ViewController(IntPtr handle) : base(handle)
            {
                // Note: this .ctor should not contain any initialization logic.
            }
    
            public override void ViewDidLoad()
            {
                base.ViewDidLoad();
                _mediaPicker = new MediaPicker();
                // Perform any additional setup after loading the view, typically from a nib.
                TakePictureButton.TouchUpInside += (sender, e) => TakePictureHandler();
            }
    
            public override void DidReceiveMemoryWarning()
            {
                base.DidReceiveMemoryWarning();
                // Release any cached data, images, etc that aren't in use.
            }
    
            async void TakePictureHandler()
            {
                try
                {
                    if (_mediaPicker.IsCameraAvailable)
                    {
                        // Do stuff - **Gets here**
                        await _mediaPicker.TakePhotoAsync(BuildMediaOptions()).ContinueWith(t =>
                        {
                            Console.WriteLine("HELLO!");
                        });
                    }
                    else
                    {
                        new UIAlertView("No Camera", "There is no camera available on this device.", null, "OK", null).Show();
                    }
                }
                catch (Exception ex)
                {
                    // Catch stuff, print exception - **Doesn't get here**
                    Console.WriteLine(ex);
                }
                finally
                {
                    // Finalize stuff - **Or here**
                }
            }
    
            protected virtual StoreCameraMediaOptions BuildMediaOptions()
            {
                var options = new StoreCameraMediaOptions
                {
                    Name = string.Format("ds_{0}", Guid.NewGuid()),
                    Directory = "MoboFlowImages"
                };
                return options;
            }
        }
    }
    

    This is the output when it dies:

    ================================================================= Got a SIGABRT while executing native code. This usually indicates a fatal error in the mono runtime or one of the native libraries used by your application. =================================================================

    Thursday, September 15, 2016 6:53 PM
  • User84300 posted

    Did you set the new privacy settings?

    Thursday, September 15, 2016 7:26 PM
  • User33143 posted

    @TimBarton said: Did you set the new privacy settings?

    I didn't set any privacy settings, so can you be more specific? Do I need to set some privacy settings to get the camera code to work?

    Thursday, September 15, 2016 7:39 PM
  • User84300 posted

    Yes. IOS 10 requires setting new privacy settings. http://useyourloaf.com/blog/privacy-settings-in-ios-10/#disqus_thread

    Thursday, September 15, 2016 8:10 PM
  • User33143 posted

    @TimBarton said: Yes. IOS 10 requires setting new privacy settings. http://useyourloaf.com/blog/privacy-settings-in-ios-10/#disqus_thread

    Beautiful. Thank you kindly.

    Thursday, September 15, 2016 8:25 PM