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,564
  • 146
  • 81
  • 122
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 Manek Oct 04 '16 at 07:38
  • For SwiftUI-https://stackoverflow.com/questions/57110290/how-to-pick-image-from-gallery-in-swiftui/75006863#75006863 – Gurjinder Singh Jan 04 '23 at 16:14

8 Answers8

5

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
  • 378
  • 5
  • 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,139
  • 4
  • 31
  • 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
  • 904
  • 8
  • 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,491
  • 11
  • 29
Thomas Decaux
  • 21,738
  • 2
  • 113
  • 124
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
  • 600
  • 1
  • 7
  • 14
0

No need for a 3rd party library. You can use PHPickerViewController. https://developer.apple.com/documentation/photokit/phpickerviewcontroller

 private func showImagePicker() {
        var configuration = PHPickerConfiguration()
        configuration.selectionLimit = 5 // Selection limit. Set to 0 for unlimited.
        configuration.filter = .images // he types of media that can be get.
        let picker = PHPickerViewController(configuration: configuration)
        picker.delegate = self
        present(picker, animated: true)
    }
Alvin John
  • 403
  • 4
  • 14
0

Apple introduced PHPickerViewController in iOS14.

Advantages

  • No additional permission need to be implemented (its private by default)
  • Supports Multi-selection (limit can also be specified)
  • Zooming and previewing the selection

Documentation - https://developer.apple.com/documentation/photokit/phpickerviewcontroller
Video - https://developer.apple.com/videos/play/wwdc2020/10652/

Hope this helps!

Naveen T P
  • 6,955
  • 2
  • 22
  • 29
-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
  • 398,270
  • 210
  • 566
  • 880
Forrest
  • 122,703
  • 20
  • 73
  • 107