Is there a way in Xamarin.Forms iOS to take photo or select image from Gallery?
Same functionality when you open a camera in the device. It will give you ability to take a photo or open gallery.
For now, we recommend using Xamarin.Essentials: Media Picker,just as Jason mentioned.
The MediaPicker
class let us pick or take a photo or video on the device.
To start using this API, read the getting started guide for Xamarin.Essentials to ensure the library is properly installed and set up in your projects.
And to access the MediaPicker functionality the following platform specific setup is required.
In IOS, add the following keys in your `Info.plist`:
<key>NSCameraUsageDescription</key>
<string>This app needs access to the camera to take photos.</string>
<key>NSMicrophoneUsageDescription</key>
<string>This app needs access to microphone for taking videos.</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>This app needs access to the photo gallery for picking photos and videos.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>This app needs access to photos gallery for picking photos and videos.</string>
Note:Ensure that you update the <string>
in each to a description specific for your app as it will be shown to your users.
And the MediaPicker
class has the following methods that all return a FileResult
that can be used to get the files location or read it as a Stream.
PickPhotoAsync: Opens the media browser to select a photo.
CapturePhotoAsync: Opens the camera to take a photo.
PickVideoAsync: Opens the media browser to select a video.
CaptureVideoAsync: Opens the camera to take a video.
For more, you can check document:https://learn.microsoft.com/en-us/xamarin/essentials/media-picker?context=xamarin%2Fandroid&tabs=ios .