问题
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