Home > other >  How to set the location for the captured photo by using UIImagePickerController
How to set the location for the captured photo by using UIImagePickerController

Time:09-16

How to set the location for the captured photo by using UIImagePickerController?

I have an app that has the option to take a photo or grab one from the phones gallery. If I selsct one from the gallery I can see the GPS data in the info[UIImagePickerControllerReferenceURL], but when I save it to the apps documents folder it loses the GPS data. If I take a photo from within the app the info[UIImagePickerControllerReferenceURL] is nil?

CodePudding user response:

So, I assuming you want to fetch Metadata Information - Try the following snippet for this- Get UIImage MetaData

CodePudding user response:

I did lots of RND and searched here and there and tried many solutions but no luck, after googling for hours

Finally figured out with the help of https://developer.apple.com/documentation/photokit/phassetchangerequest?language=objc

public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
    picker.dismiss(animated: true)
    self.imageToSave = info[.originalImage] as? UIImage
    try? PHPhotoLibrary.shared().performChangesAndWait {
        let imgReq = PHAssetChangeRequest.creationRequestForAsset(from: self.imageToSave!)
        imgReq.location = self.location
        imgReq.isFavorite = true
     }
}
  • Related