Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

App crashes if you deny to access the camera in iOS, why?

$
0
0

Hi Everyone,
I am facing a very strange issue, When the app open it asks for the permission to access the camera and if I deny . And when i open for the camera the app crashes. Here is the snippet.

Device.BeginInvokeOnMainThread(async () =>
        {
            var action = await DisplayActionSheet("Add Photo", "Cancel", null, "Choose Existing", "Take Photo");

            if (action == "Choose Existing")
            {
                if (!CrossMedia.Current.IsPickPhotoSupported)
                {
                    await DisplayAlert("Photos Not Supported", ":( Permission not granted to photos.", "OK");
                    return;
                }
                var file = await Plugin.Media.CrossMedia.Current.PickPhotoAsync(new Plugin.Media.Abstractions.PickMediaOptions
                {
                    PhotoSize = Plugin.Media.Abstractions.PhotoSize.Medium,

                });


                if (file == null)
                    return;

                archieImg.Source = ImageSource.FromStream(() =>
                {

                    var stream = file.GetStream();
                    return stream;
                });
                archieImg.IsVisible = true;
                imgPet.IsVisible = false;
                MessagingCenter.Send(new PetModel() { ImageUrl = archieImg.Source }, "Image");
                asd = archieImg;

            }
            else if (action == "Take Photo")
            {

                if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
                {
                    await DisplayAlert("No Camera", ":( No camera avaialble.", "OK");
                    return;
                }

                var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    PhotoSize = Plugin.Media.Abstractions.PhotoSize.Medium,
                    Directory = "Sample",
                    Name = "test.jpg",
                    AllowCropping = true
                });

                if (file == null)
                    return;
                archieImg.Source = ImageSource.FromStream(() =>
                {
                    var stream = file.GetStream();
                    return stream;
                });
                archieImg.IsVisible = true;
                imgPet.IsVisible = false;
                MessagingCenter.Send(new PetModel() { ImageUrl = archieImg.Source }, "Image");
                asd = archieImg;
            }
        });

Thanks


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>