AssetsPickerViewController icon indicating copy to clipboard operation
AssetsPickerViewController copied to clipboard

Maximum asset selection for photos and videos (separate)

Open coder123-star opened this issue 4 years ago • 2 comments

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.

coder123-star avatar Nov 21 '20 19:11 coder123-star

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
    }

gezihuzi avatar Dec 13 '20 10:12 gezihuzi

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
    }

Priyanka-gupta-pcg avatar Dec 17 '20 06:12 Priyanka-gupta-pcg