hyperoslo / ImagePicker

:camera: Reinventing the way ImagePicker works.
Other
4.87k stars 677 forks source link

Picker gets no image when selected image is in iCloud #315

Closed RealHacker closed 4 years ago

RealHacker commented 7 years ago

When the user's photo is stored in iCloud, after selecting thumbnails, and tap Done button, the images returned is a blank array.

The problem is in AssetManager.swift: resolveAssets:, when the image is in iCloud, in the callback, image is nil, and info has PHImageResultIsInCloudKey set to true.

But it's said the flag is not reliable: https://stackoverflow.com/questions/28482275/how-to-identify-if-a-phasset-is-not-completely-downloaded-from-icloud-so-i-need

Another question unrelated to this bug: in resolveAsset, there is a condition info["PHImageFileUTIKey"] == nil, what is this used for?

PGLongo commented 7 years ago

Same issue here. I've temporary fix in this adding requestOptions.isNetworkAccessAllowed = true in AssetManager. But it's not the best solution, because the UI became unresponsive during image download

 open static func resolveAssets(_ assets: [PHAsset], size: CGSize = CGSize(width: 720, height: 1280)) -> [UIImage] {
    let imageManager = PHImageManager.default()
    let requestOptions = PHImageRequestOptions()
    requestOptions.isSynchronous = true
    requestOptions.isNetworkAccessAllowed = true

    var images = [UIImage]()
    for asset in assets {
      imageManager.requestImage(for: asset, targetSize: size, contentMode: .aspectFill, options: requestOptions) { image, info in
        if let image = image {
          images.append(image)
        }
      }
    }
    return images
  }
RealHacker commented 7 years ago

Normally (in apps with photo selection), a progress indicator is shown when downloading an image from iCloud, upon user tapping a thumbnail.

PGLongo commented 7 years ago

Sure, it should be added in ImagePickerController.doneButtonDidPress

loloabj commented 7 years ago

I'm trying to add the progress indicator into ImagePickerController.doneButtonDidPress but I don't know exactly how to proceed. Does the solution consists in embedding the content of ImagePickerController.doneButtonDidPress into another function with a completion handler, and moving the call to delegate?.doneButtonDidPress in ImagePickerController.doneButtonDidPress after the completion is called ?

Huddie commented 7 years ago

Any real fix for this yet? Any good work arounds?

dannyshmueli commented 7 years ago

+1

jkufver commented 6 years ago

I did this to fix the issue I saw on my iPhone 6+ ios 11.1, iCloud image sync enabled with little storage left:

    open static func resolveAssets(_ assets: [PHAsset], size: CGSize = CGSize(width: 720, height: 1280), completion: @escaping (_ image: [UIImage]) -> Void) {
        DispatchQueue.global(qos: .userInitiated).async {
            let imageManager = PHImageManager.default()
            let requestOptions = PHImageRequestOptions()
            requestOptions.isSynchronous = true
            requestOptions.isNetworkAccessAllowed = true

            var images = [UIImage]()
            for asset in assets {
                imageManager.requestImage(for: asset, targetSize: size, contentMode: .aspectFill, options: requestOptions) { image, _ in
                    if let image = image {
                        images.append(image)
                    }
                }
            }

            DispatchQueue.main.async {
                completion(images)
            }
        }
    }

rewrite the calling code like this:

            AssetManager.resolveAssets(stack.assets, size: preferredImageSize) { [weak self] in
                if let weakSelf = self {
                    weakSelf.delegate?.wrapperDidPress(weakSelf, images: $0)
                }
            }
jkufver commented 6 years ago

... maybe an UIActivityIndicator should be added as well, because the async stuff sometimes takes seconds on my phone when I select images which have to be downloaded from iCloud.

dfabreguette commented 6 years ago

+1 any idea when that can be merged ? Still have the issue on 3.0.0 version :/

jkufver commented 6 years ago

Hi, I have no plan of doing a patch. First I had but then I read the instructions on how to (and rules) and lost the spirit.

I duplicated the code and fixed the errors locally.

Br / Jens

24 maj 2018 kl. 11:57 skrev David Fabreguette notifications@github.com:

+1 any idea when that can be merged ? Still have the issue on 3.0.0 version :/

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/hyperoslo/ImagePicker/issues/315#issuecomment-391658318, or mute the thread https://github.com/notifications/unsubscribe-auth/AFV7P54Hf6VcTy9KPPwzDdpN5gtYjVsbks5t1oP-gaJpZM4ONCec.

dfabreguette commented 6 years ago

Just pushed a fix !