Get an edited photo's URL from PHAsset

元气小坏坏 提交于 2019-12-06 08:20:06

问题


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?


回答1:


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`
  })


来源:https://stackoverflow.com/questions/46982650/get-an-edited-photos-url-from-phasset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!