MediaPicker is a SPM which fills the gap of Apples UIPickerViewController. It provides us the functionality to select multiple media assets at a time.
Implementation of MediaPicker is really easy and simple. So in-order to present Media Picker we initially need to create a configuration for it.
So there are two form of configuration in media picker.
- MediaPicker System Config
This involves the internal configuration required for Media Picker. We need to be very careful when selecting this configurations, since this would directly lead to app perfomance.
- MediaPicker Config
MediaPicker config includes the System config along with basic configurations required for Media Picker. Eg: Selection Limit & Media types to fetch
Once you are done with the configuration, then you just need to present the MediaPicker. Now presentation of media picker includes two methods
- Delegation Based
Here present the picker normally, and confirm to its delegate, and you will be able to use the necessary methods.
Make sure you go through the code and understand what are the different types of configurations
- Completion Based
Here an extension is written for MediaPicker, which can be directly used to present it
Now all you need to do is configure your code as per the need.
In our codebase, implementation of MediaPicker is done via DeviceImagePicker. So there is no need of direct implementation of the same.
Lets understand how under the hood Media Picker works with the following flow chart:
Initially Media Picker check for the Authorisation status, accordingly it takes the action. If Request is granted then the MPStoreManager will fetch all the assets and start rendering. If request is not determined then it will ask for permission and finally if access is restricted it will throw error.