从ios swift中的图像获取位置详细信息
Posted
技术标签:
【中文标题】从ios swift中的图像获取位置详细信息【英文标题】:Getting location details from image in ios swift 【发布时间】:2017-12-12 06:15:36 【问题描述】:我正在尝试使用从图像中获取位置详细信息
UIImagePickerControllerReferenceURL
但我发现 PHAsset.fetchAssets(withALAssetURLs: [URL], options: opts)
已被弃用。请帮助我获取位置详细信息。
我们可以使用PHAssetCollection
吗?如果是请帮助我
public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])
print(info)
let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage
selectedImage.contentMode = .scaleAspectFit
selectedImage.image = chosenImage
dismiss(animated:true, completion: nil)
if let URL = info[UIImagePickerControllerReferenceURL] as? URL
let opts = PHFetchOptions()
opts.fetchLimit = 1
let assets = PHAsset.fetchAssets(withALAssetURLs: [URL], options: opts)
let asset = assets[0]
print(asset.location)
// The location is "asset.location", as a CLLocation
// ... Other stuff like dismiss omitted
【问题讨论】:
另一种选择是您可以将图像保存到 doc 目录并使用该路径。 【参考方案1】:到目前为止,我发现的唯一解决方案是即使在 ios 11 中也使用 iOS 10 代码块,而忽略 UIImagePickerControllerReferenceURL
deprecated 消息(密钥仍然存在并在 iOS 11 中有效)
import AssetsLibrary
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])
if let imageUrl = info[UIImagePickerControllerReferenceURL] as? NSURL
print(imageUrl.absoluteString) //"assets-library://asset/asset.JPG?id=ED7AC36B-A150-4C38-BB8C-B6D696F4F2ED&ext=JPG"
// access image from URL
let assetLibrary = ALAssetsLibrary()
assetLibrary.asset(for: imageUrl as URL! , resultBlock: (asset: ALAsset!) -> Void in
if let actualAsset = asset as ALAsset?
let assetRep: ALAssetRepresentation = actualAsset.defaultRepresentation()
let iref = assetRep.fullResolutionImage().takeUnretainedValue()
let image = UIImage.init(cgImage: iref)
self.img.image = image
, failureBlock: (error) -> Void in
)
dismiss(animated: true, completion: nil)
希望这会有所帮助。
【讨论】:
以上是关于从ios swift中的图像获取位置详细信息的主要内容,如果未能解决你的问题,请参考以下文章
使用 PFFacebookUtils 和 Swift 和 iOS 9 获取 Facebook 帐户详细信息