从PHAsset获取经过编辑的照片的URL

Mob*_*tar 3 avfoundation ios swift phasset

我正在尝试通过PHAsset使用此代码获取照片的URL 。

 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`
  })
Run Code Online (Sandbox Code Playgroud)

大多数照片与此代码配合良好。

当我在“相机”应用中拍摄照片并在“照片”应用中旋转照片,然后在我的应用中选择旋转的照片时,此代码返回原始照片URL,而不是旋转的版本。

如何从中获取经过编辑的照片的本地URL PHAsset

mik*_*396 5

Try changing your return to "false"

如果您的区块返回true,则“照片”会提供原始资产数据进行编辑。您的应用使用调整数据来更改,添加或重新应用以前的编辑。(例如,调整数据可能描述了应用于照片的滤镜。您的应用会重新应用这些滤镜,并允许用户更改滤镜参数,添加新的滤镜或删除滤镜。)

如果块返回false,则Photos将提供最新的资产数据(所有先前编辑的渲染输出)进行编辑。

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`
  })
Run Code Online (Sandbox Code Playgroud)