user979331
user979331

Reputation: 11951

Xamarin Forms - MediaPlugin - Photo Picker Permissions not working as expected

I am using Xamarin.Forms and MediaPlugin https://github.com/jamesmontemagno/MediaPlugin and here is my code:

if (!CrossMedia.Current.IsPickPhotoSupported)
                {
                    await DisplayAlert("Photos Not Supported", "Sorry! Permission not granted to photos.", "OK");
                    return;
                }

                MediaFile file = null;

                if (await Permissions.RequestAsync<Permissions.Photos>() == Xamarin.Essentials.PermissionStatus.Granted)
                {
                    file = await Plugin.Media.CrossMedia.Current.PickPhotoAsync(new Plugin.Media.Abstractions.PickMediaOptions
                    {
                        PhotoSize = Plugin.Media.Abstractions.PhotoSize.Medium,

                    });
                }

                if (file == null)
                    return;

                var imageSource = ImageSource.FromStream(() =>
                {
                    var stream = file.GetStream();
                    return stream;
                });

                PickImage.Source = imageSource;

This gives me a permission dialog like so:

enter image description here

When I select "Select Photos..." And then select the photos that i am allowing the app to use, the library comes up again and I am allow to select any photo I want, even the ones I did not select the first time around.

Is this the expected behaviour for Select Photos..., is there away I can remove the Select Photos... option?

Upvotes: 1

Views: 829

Answers (1)

Juan Sturla
Juan Sturla

Reputation: 1304

That package is no longer mantained, so it's not sure that it works as intended.

You should migrate to Xamarin.Essentials MediaPicker. It will handle the permission request automatically for you.

Also it seems that you are already using Xamarin.Essentials.

Make sure that you follow the steps detailed on the documentation. That means modifying the info.plist.

Upvotes: 1

Related Questions