coders
coders

Reputation: 2477

PHImageManager is sending duplicated photos

My code as below. It is sending duplicated photos 1) high quality and 2) low quality. Just want to understand why this library is doing that ?

      PHImageManager.default().requestImage(for: asset, targetSize: size, contentMode: .aspectFit, options: nil) { result, info in
    guard let image = result else {
      return
    }

    self.sendPhoto(image)
  }

enter image description here

FIXed by to force the options to send a quality

fileprivate func imageRequestOptions() -> PHImageRequestOptions {
    let requestOption = PHImageRequestOptions()
    requestOption.deliveryMode = .highQualityFormat
    return requestOption
}

PHImageManager.default().requestImage(for: asset, targetSize: size, contentMode: .aspectFit, options: self.imageRequestOptions()) { result, info in
            guard let image = result else {
                return
            }

            self.sendPhoto(image)
            print("sendPhoto iOS 11.0 * asset")
        }

Upvotes: 1

Views: 168

Answers (1)

From the document of Apple

For an asynchronous request, Photos may call your result handler block more than once. Photos first calls the block to provide a low-quality image suitable for displaying temporarily while it prepares a high-quality image. (If low-quality image data is immediately available, the first call may occur before the method returns.) When the high-quality image is ready, Photos calls your result handler again to provide it. If the image manager has already cached the requested image at full quality, Photos calls your result handler only once. The PHImageResultIsDegradedKey key in the result handler’s info parameter indicates when Photos is providing a temporary low-quality image. You can use this method for both photo and video assets—for a video asset, an image request provides a thumbnail image or poster frame.

Maybe this is business of them. I think we should note with this case

Upvotes: 1

Related Questions