Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get an edited photo's URL from PHAsset

I'm trying to get a photo's URL from a PHAsset using this code.

 let options: PHContentEditingInputRequestOptions = PHContentEditingInputRequestOptions()
 options.canHandleAdjustmentData = {(adjustmeta: PHAdjustmentData) -> Bool in
          return true
  }

  asset.requestContentEditingInput(with: options, completionHandler: { (contentEditingInput, info) in
          guard let url = contentEditingInput?.fullSizeImageURL else {
               observer.onError(PHAssetError.imageRequestFailed)
               return
          }
          /// Using this `url`
  })

Most of the photos are working well with this code.

When I take a photo in the Camera app and rotate the photo in the Photos app, then select the rotated photo in my app, this code returns the original photo URL -- not the rotated version.

How can I get the edited photo's local URL from PHAsset?

like image 500
Max Wang Avatar asked Mar 07 '23 17:03

Max Wang


1 Answers

Try changing your return to "false"

If your block returns true, Photos provides the original asset data for editing. Your app uses the adjustment data to alter, add to, or reapply previous edits. (For example, an adjustment data may describe filters applied to a photo. Your app reapplies those filters and allows the user to change filter parameters, add new filters, or remove filters.)

If your block returns false, Photos provides the most recent asset data—the rendered output of all previous edits—for editing.

https://developer.apple.com/documentation/photos/phcontenteditinginputrequestoptions/1624055-canhandleadjustmentdata

 let options: PHContentEditingInputRequestOptions = PHContentEditingInputRequestOptions()
 options.canHandleAdjustmentData = {(adjustmeta: PHAdjustmentData) -> Bool in
          return false
  }

  asset.requestContentEditingInput(with: options, completionHandler: { (contentEditingInput, info) in
          guard let url = contentEditingInput?.fullSizeImageURL else {
               observer.onError(PHAssetError.imageRequestFailed)
               return
          }
          /// Using this `url`
  })
like image 163
mikemike396 Avatar answered Mar 18 '23 13:03

mikemike396