Saturday, November 21, 2026
HomeiOS Developmentios - PhotoKit: get full decision offline asset preview, when the requested...

ios – PhotoKit: get full decision offline asset preview, when the requested asset is in iCloud

[ad_1]

When loading pictures from the picture library by way of PhotoKit, it could actually occur that the picture just isn’t downloaded from iCloud. On this case, a low-resolution “placeholder” model of that picture is offered domestically if you happen to browse it within the photographs App:

enter image description here

Nonetheless, when I attempt to get the identical picture to show in an app, the picture that I get from PHAssetManager shall be at most 120 items extensive (or excessive). This appears to be like very blurry and is totally unusable apart from a thumbnail.

Blurry image in app

I’ve already tried

  • PHImageManagerMaximumSize because the goal dimension
  • resizeMode = .none and .actual
  • all of the deliveryMode‘s
  • requestImageDataAndOrientation
  • to learn the picture information another way, e.g. by privateFileURL property on the asset

I wished to ask if anybody has come throughout this concern and possibly labored round it.

The habits could be simply reproduced with some PhotoKit instance app, for instance from these course supplies.
That is the code I used to provide the under picture:


extension UIImageView {
  func fetchImageAsset(_ asset: PHAsset?, targetSize dimension: CGSize, contentMode: PHImageContentMode = .aspectFill, completionHandler: ((Bool) -> Void)?) {

    let choices = PHImageRequestOptions()
    choices.deliveryMode = .opportunistic
    choices.resizeMode = .none
    choices.isNetworkAccessAllowed = false

    // 1
    guard let asset = asset else {
      completionHandler?(false)
      return
    }
    // 2
    let resultHandler: (UIImage?, [AnyHashable: Any]?) -> Void = { picture, data in
      if let picture = picture {
        self.picture = picture
      }
      completionHandler?(true)
    }
    // 3
    PHImageManager.default().requestImage(
      for: asset,
      targetSize: dimension,
      contentMode: contentMode,
      choices: choices,
      resultHandler: resultHandler)
  }
}

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments