4

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?

jscs
  • 63,694
  • 13
  • 151
  • 195
Max Wang
  • 247
  • 3
  • 16

1 Answers1

7

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`
  })
mikemike396
  • 2,435
  • 1
  • 26
  • 41
  • 1
    Great! We actually ran into this same issue and started digging into the docs and found this. Glad we could help! – mikemike396 Oct 30 '17 at 02:00