我正在尝试从 ALAssetsLibrary 转换为 PHPhotoLibrary,因为它已被弃用。我需要从照片库中选择一张照片中获取日期,但无法找出正确的方法。这是我目前的做法。
mediaUrl = info[UIImagePickerControllerReferenceURL] as? NSURL
...
let assetsLibrary = ALAssetsLibrary()
assetsLibrary.assetForURL(mediaUrl, resultBlock: { (asset) -> Void in
guard let asset = asset else { return }
guard let date = asset.valueForProperty(ALAssetPropertyDate) as? NSDate else { return }
let dateString = dateFormatter.stringFromDate(date)
//---- use date string here
}) { (error) -> Void in
print(error)
}
这是我到达的地方:
let photoLibrary = PHPhotoLibrary.sharedPhotoLibrary()
var photoAssetPlaceholder: PHObjectPlaceholder!
photoLibrary.performChanges({
let request = PHAssetChangeRequest.creationRequestForAssetFromImage(image)
photoAssetPlaceholder = request.placeholderForCreatedAsset
}, completionHandler: { success, error in
if success {
print (photoAssetPlaceholder)
//How do I get date from PhotoAssetPlaceholder???
} else {
print(error?.localizedDescription)
}
})
我觉得我很接近了。任何帮助,将不胜感激!