ytakzk / Fusuma

Instagram-like photo browser and a camera feature with a few line of code in Swift.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fusumaMultipleImageSelected not getting called.

StellarKuldeep opened this issue · comments

I'm trying to allow the user to select multiple images and for that I have tried below code.

let fusuma = FusumaViewController()
fusuma.delegate = self
fusuma.cropHeightRatio = 1.0
fusuma.allowMultipleSelection = true
fusuma.availableModes = [.library, .video, .camera]
fusuma.photoSelectionLimit = 4
fusumaTintColor = UIColor.red
fusumaSavesImage = true

present(fusuma, animated: true, completion: nil)

If I write fusuma.allowMultipleSelection = false then delegate getting called but when I have tried fusuma.allowMultipleSelection = true then delegate not getting called.

// MARK: FusumaDelegate Protocol
    func fusumaImageSelected(_ image: UIImage, source: FusumaMode) {
        switch source {
        case .camera:
            print("Image captured from Camera")
        case .library:
            print("Image selected from Camera Roll")
        default:
            print("Image selected")
        }

        imageView.image = image
    }

    func fusumaMultipleImageSelected(_ images: [UIImage], source: FusumaMode) {
        print("Number of selection images: \(images.count)")

        var count: Double = 0

        for image in images {
            DispatchQueue.main.asyncAfter(deadline: .now() + (3.0 * count)) {
                self.imageView.image = image
                print("w: \(image.size.width) - h: \(image.size.height)")
            }

            count += 1
        }
    }

I tried this in downloaded demo but it's not working.

commented

+1, dont worked

You need to use the following method to get callbacks:

func fusumaMultipleImageSelected(_ images: [UIImage], source: FusumaMode, metaData: [ImageMetadata]) {

}

Note that this method has metaData property. There is an error in the protocol that it is only pulling up the method without the metaData. If you examine the FusumaViewController you'll see that the non metaData version is never called. Using the above method resolves it straight away.

This should probably be fixed. The required protocol stub for the delegate is:

is func fusumaMultipleImageSelected(_ images: [UIImage], source: FusumaMode) {

}

Not

func fusumaMultipleImageSelected(_ images: [UIImage], source: FusumaMode, metaData: [ImageMetadata]) {

}