Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get all photos? #78

Closed
davin12x opened this issue Feb 26, 2016 · 8 comments
Closed

Cannot get all photos? #78

davin12x opened this issue Feb 26, 2016 · 8 comments

Comments

@davin12x
Copy link

Hi . I m facing a problem . When i selected multiple photo e.x 18 photos selected ..It return me less photo instead of all.Here is my code
let pickerController = DKImagePickerController()
var images:[UIImage] = []

pickerController.didSelectAssets = { (assets: [DKAsset]) in
print(assets.count) // This return me exact same value which i select
for asset in assets {
asset.fetchOriginalImageWithCompleteBlock({ (image, info) -> Void in
print(image) //return less images
self.images.append(image!)
print(self.images.count) //Return less images count
})
}
}
self.presentViewController(pickerController, animated: true) {}

can u help me out . Am i wrong someWhere ?

@zhangao0086
Copy link
Owner

The fetchOriginalImageWithCompleteBlock method is executed on a background thread. You should print the self.images.count after the all fetchOriginalImageWithCompleteBlock are completed.

@davin12x
Copy link
Author

it still same .. But when i use this code
for asset in assets {
asset.fetchImageWithSize(CGSize(width: 200, height: 200), options: PHImageRequestOptions?.init(), completeBlock: { (image, info) -> Void in
self.images.append(image!)
})
This give me all the value. When i change the CZsize according to original image. Then it again gives me less value

@zhangao0086
Copy link
Owner

Try this:

pickerController.didSelectAssets = { (assets: [DKAsset]) in
    print(assets.count)

    dispatch_async(dispatch_get_global_queue(0, 0), {
        let options = PHImageRequestOptions()
        options.deliveryMode = .HighQualityFormat
        options.synchronous = true

        for (_, asset) in assets.enumerate() {
            asset.fetchImageWithSize(PHImageManagerMaximumSize, options: options) { image, info in
                self.images.append(image!)
            }
        }

        print(self.images.count)
    })
}

@davin12x
Copy link
Author

scren
thanks for replying . i used this code and most of time it crashed when selecting more than 1 photo..But some time it works ..

@zhangao0086
Copy link
Owner

Could you post the error stacktrace?

@davin12x
Copy link
Author

stack trace
i think i have infinite loop is going on there...I really appreciate that you are helping me

As you can see i selected 19 photos there

@zhangao0086
Copy link
Owner

Could you try to replace the condition

if let isInCloud = info?[PHImageResultIsInCloudKey]?.boolValue
    where isInCloud && self.autoDownloadWhenAssetIsInCloud {

to

if let isInCloud = info?[PHImageResultIsInCloudKey]?.boolValue
    where image == nil && isInCloud && self.autoDownloadWhenAssetIsInCloud {

Let me know if that works :)

@davin12x
Copy link
Author

You are awesome. THANKS A LOT !!!! YOU saved my life. I was scratching my head ..calling my self totaly dumb..Thanks ..So the problem was downloading images from cloud ..Thanks Again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants