19

In iPhone OS 3.0, Apple added the ability to share multiple pictures at once using the "Share" button and selecting multiple images (where a checkmark is used).

I'd love to have a UIImagePickerController which lets the user select multiple images at once, rather than having to go one by one. Is there a way to do this, or do I have to wait until they add this feature?

Pang
  • 9,073
  • 146
  • 84
  • 117
Itay
  • 1,669
  • 5
  • 18
  • 23
  • Similar question: http://stackoverflow.com/questions/1823698/how-to-select-multiple-image-with-uiimagepickercontroller – Arne Evertsson Mar 03 '10 at 13:20
  • 1
    Check complete list for Objective-C and Swift library here, http://stackoverflow.com/a/20756957/1903074 . hope this will help some one. – Dilip Oct 04 '16 at 07:38

6 Answers6

4

If you are supporting only iOS 14 and up, you can use Apple's PHPickerViewController. It allows multiple image selection (while UIImagePickerController does not).

An additional benefit to using PHPickerViewController vs other libraries listed above is that the user will not need to grant permission to access your photo library.

Andy Novak
  • 268
  • 4
  • 11
2

Try this wonderful API in swift: ImagePicker. As all other image APIs, it is simple to use and it is very well updated.

Utsav Dusad
  • 2,019
  • 4
  • 26
  • 52
2

1.install pod - pod "BSImagePicker", "~> 2.8"

  1. inside info plist add row Privacy - Photo Library Usage Description

3.paste below code inside a .swift file-

    import UIKit
    import BSImagePicker
    import Photos

    class MultipleImgViC: UIViewController {

        @IBOutlet weak var imageView: UIImageView!
        var SelectedAssets = [PHAsset]()
        var photoArray = [UIImage]()


        override func viewDidLoad() {
            super.viewDidLoad()


        }




        @IBAction func selectImages(_ sender: Any) {

            let vc = BSImagePickerViewController()

            self.bs_presentImagePickerController(vc, animated: true, select: { (assest: PHAsset) -> Void in
            },
                                                 deselect: { (assest: PHAsset) -> Void in

        }, cancel: { (assest: [PHAsset]) -> Void in

        }, finish: { (assest: [PHAsset]) -> Void in

            for i in 0..<assest.count
            {
                    self.SelectedAssets.append(assest[i])
            }

            self.convertAssetToImages()

        }, completion: nil)


    }


    @IBAction func dismissview(_ sender: Any) {
        dismiss(animated: true, completion: nil)
    }


}
extension MultipleImgViC{

    func convertAssetToImages() -> Void {

        if SelectedAssets.count != 0{

            for i in 0..<SelectedAssets.count{

                let manager = PHImageManager.default()
                let option = PHImageRequestOptions()

                var thumbnail = UIImage()

                option.isSynchronous = true

                manager.requestImage(for: SelectedAssets[i], targetSize: CGSize(width: 200, height: 200), contentMode: .aspectFill, options: option, resultHandler: {(result,info) -> Void in
                    thumbnail = result!
                })

                let data = thumbnail.jpegData(compressionQuality: 0.7)
                let newImage = UIImage(data: data!)
                self.photoArray.append(newImage! as UIImage)

            }

            self.imageView.animationImages = self.photoArray
            self.imageView.animationDuration = 3.0
            self.imageView.startAnimating()
        }

    }


}

Note :- if pod file give "How to fix “SWIFT_VERSION '3.0' is unsupported, supported versions are: 4.0, 4.2, 5.0” error in Xcode 10.2? " this error then solve it from this link:- https://stackoverflow.com/a/55901964/8537648

video reference: - https://youtu.be/B1DelPi1L0U

sample image:-enter image description here

Govind Wadhwa
  • 764
  • 5
  • 16
1

AssetLibrary + UICollectionView ^^

Basically, with StoryBoard, you import aUINavigationController, you change the root controller to anUICollectionViewController (will be your Album list), end add anotherUICollectionViewController (will be your photos list).

Then with Assetlibrary you retrieve user albums and user album content.

I will make a such component as soon as i have some time.

Ashok Londhe
  • 1,482
  • 11
  • 29
Thomas Decaux
  • 19,993
  • 2
  • 99
  • 107
1

You can use this OpalImagePicker like this (Swift 4):

 var imagePicker: OpalImagePickerController! 
 imagePicker = OpalImagePickerController()
 imagePicker.imagePickerDelegate = self
 imagePicker.selectionImage = UIImage(named: "aCheckImg")
 imagePicker.maximumSelectionsAllowed = 3 // Number of selected images
 present(imagePicker, animated: true, completion: nil)

And then implement its delegate:

func imagePickerDidCancel(_ picker: OpalImagePickerController) {
        //Cancel action
}

func imagePicker(_ picker: OpalImagePickerController, didFinishPickingImages images: [UIImage]) {
}
Letaief Achraf
  • 520
  • 1
  • 6
  • 14
-18

How about this way:

  1. Open "photos.app" first, select multiple photos , and copy them ;

  2. In your own app, try to retrieve those copies photos;

I knew that there are some apps did like this, but do not know how can achieve step 2.

Bill the Lizard
  • 386,424
  • 207
  • 554
  • 861
Forrest
  • 113,461
  • 20
  • 72
  • 107