DragonCherry / AssetsPickerViewController

Powerfully Customizable - Multiple Photo & Video Picker Controller
MIT License
388 stars 136 forks source link

Maximum asset selection for photos and videos (separate) #95

Open coder123-star opened 3 years ago

coder123-star commented 3 years ago

Similar to an app like twitter I would like to only allow users to upload one video however they can select multiple images and upload them. I don't know how to do this though since there is only maximum and minimum selection for all assets.

gezihuzi commented 3 years ago

You can do this by delegate the method func assetsPicker(controller: AssetsPickerViewController, shouldSelect asset: PHAsset, at indexPath: IndexPath) -> Bool to achieve this.

Look like this:

   func assetsPicker(controller: AssetsPickerViewController, shouldSelect asset: PHAsset, at indexPath: IndexPath) -> Bool {
        if controller.selectedAssets.count >= 1 {
            return false
        }
        return true
    }
Priyanka-gupta-pcg commented 3 years ago

found solution -


   func assetsPicker(controller: AssetsPickerViewController, shouldSelect asset: PHAsset, at indexPath: IndexPath) -> Bool {
        // can limit selection count
        if asset.mediaType == .video {
            if controller.selectedAssets.count > 4 {
                return false
            }
        }
        if asset.mediaType == .image {
            if controller.selectedAssets.count > 7 {
                return false
            }
        }
        return true
       }