0

I am taking a photo with the camera and UIImagePickerController and then saving it to the photo albums with

@objc func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

    ImagePicker.dismiss(animated: true, completion: nil)
    photoChanged = true

    let image: UIImage = info[UIImagePickerControllerOriginalImage] as! UIImage
    let compressedImage = image.resizeWithWidth(width: 450)
    let ext: String = "JPEG"

    UIImageWriteToSavedPhotosAlbum(image, self, #selector(image(image:didFinishSavingWithError:contextInfo:)), nil)
    submittedPhoto = Photo(photo: compressedImage, ext: ext, key: nil, idx: nil, postId: post?.postId)

    if let cell = tableView.cellForRow(at: IndexPath(row: 1, section: 0)) as? SubmitHunterTVC {

        cell.addPhotoB.iconImageView.image = image
        cell.addPhotoB.iconImageView.contentMode = .scaleAspectFill
        cell.addPhotoB.clipsToBounds = true
    }
    tableView.reloadData()
}

When I retrieve the asset and check the location I get empty {GPS} information from the EXIF and the asset.

E7F0DDE0-3A89-4E77-AF0C-2AED2A4F96FF/L0/001 mediaType=1/0, sourceType=1, (3024x4032), creationDate=2018-03-18 22:19:36 +0000, location=0, hidden=0, favorite=0

Shivam Tripathi
  • 1,405
  • 3
  • 19
  • 37
samuscarella
  • 89
  • 2
  • 9

1 Answers1

0

There was a good answer for it HERE, Below is some of the code from that answer, it will probably need to be updated to current syntax:

func addAsset(image: UIImage, location: CLLocation? = nil) {
    PHPhotoLibrary.shared().performChanges({
        // Request creating an asset from the image.
        let creationRequest = PHAssetChangeRequest.creationRequestForAsset(from: image)
        // Set metadata location
        if let location = location {
            creationRequest.location = location
        }
    }, completionHandler: { success, error in
        if !success { NSLog("error creating asset: \(error)") }
    })
}
Jake
  • 2,126
  • 1
  • 10
  • 23