如何获取从 Swift 中的 UIImagePickerController 中选择的照片的 CLLocation?
How can I get the CLLocation of a photo selected from UIImagePickerController in Swift?
UIImagePickerController 从用户的照片库中选择一张图片,
我只想获取所选照片的位置坐标,在Swift...
我已经尝试过尝试获取照片的 url...
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
let imageURL = editingInfo![UIImagePickerControllerReferenceURL] as! NSURL
self.imageFromAsset(imageURL)
}
并将其传递给...
func imageFromAsset(nsurl: NSURL) {
let asset = PHAsset.fetchAssetsWithALAssetURLs([nsurl], options: nil).firstObject as! PHAsset
var location = asset.location //then do something with this data
}
但是开始获取图像 url 会产生致命错误。
希望有人能帮忙,谢谢。
错误信息:
fatal error: unexpectedly found nil while unwrapping an Optional value
(lldb)
此错误似乎出现在这一行:
let imageURL = editingInfo![UIImagePickerControllerReferenceURL] as! NSURL
使用:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject])
而不是:
imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?)
因为它在 iOS 3.0
中已弃用
UIImagePickerController 从用户的照片库中选择一张图片,
我只想获取所选照片的位置坐标,在Swift...
我已经尝试过尝试获取照片的 url...
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
let imageURL = editingInfo![UIImagePickerControllerReferenceURL] as! NSURL
self.imageFromAsset(imageURL)
}
并将其传递给...
func imageFromAsset(nsurl: NSURL) {
let asset = PHAsset.fetchAssetsWithALAssetURLs([nsurl], options: nil).firstObject as! PHAsset
var location = asset.location //then do something with this data
}
但是开始获取图像 url 会产生致命错误。
希望有人能帮忙,谢谢。
错误信息:
fatal error: unexpectedly found nil while unwrapping an Optional value
(lldb)
此错误似乎出现在这一行:
let imageURL = editingInfo![UIImagePickerControllerReferenceURL] as! NSURL
使用:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject])
而不是:
imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?)
因为它在 iOS 3.0
中已弃用