Last active
April 2, 2025 13:33
-
-
Save eleev/2f041bb8b1936093773f0bde42af3a49 to your computer and use it in GitHub Desktop.
Getting URL for PHAsset (Swift 3.0)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getURL(ofPhotoWith mPhasset: PHAsset, completionHandler : @escaping ((_ responseURL : URL?) -> Void)) { | |
if mPhasset.mediaType == .image { | |
let options: PHContentEditingInputRequestOptions = PHContentEditingInputRequestOptions() | |
options.canHandleAdjustmentData = {(adjustmeta: PHAdjustmentData) -> Bool in | |
return true | |
} | |
mPhasset.requestContentEditingInput(with: options, completionHandler: { (contentEditingInput, info) in | |
completionHandler(contentEditingInput!.fullSizeImageURL) | |
}) | |
} else if mPhasset.mediaType == .video { | |
let options: PHVideoRequestOptions = PHVideoRequestOptions() | |
options.version = .original | |
PHImageManager.default().requestAVAsset(forVideo: mPhasset, options: options, resultHandler: { (asset, audioMix, info) in | |
if let urlAsset = asset as? AVURLAsset { | |
let localVideoUrl = urlAsset.url | |
completionHandler(localVideoUrl) | |
} else { | |
completionHandler(nil) | |
} | |
}) | |
} | |
} |
@fernandodev I recommend you add some code that shows how to use this piece. Newbies would need it, but that definitely helped. Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! I slightly changed it for what i need