【问题标题】:Swift Camera in app picture not saving GPS information when photo is saved and the asset is retrieved?保存照片并检索资产时,应用图片中的 Swift Camera 不保存 GPS 信息?
【发布时间】:2018-03-18 22:20:15
【问题描述】:

我正在用相机和 UIImagePickerController 拍照,然后用

将它保存到相册
@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()
}

当我检索资产并检查位置时,我从 EXIF 和资产中获得了空的 {GPS} 信息。

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, 最爱=0

【问题讨论】:

    标签: ios swift camera uiimagepickercontroller


    【解决方案1】:

    有一个很好的答案HERE,下面是该答案的一些代码,可能需要更新为当前语法:

    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)") }
        })
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-14
      • 2018-01-28
      • 1970-01-01
      • 1970-01-01
      • 2011-12-04
      • 2021-07-04
      相关资源
      最近更新 更多