ALAsset 已弃用 - 使用 Photos Framework 中的 PHAsset
ALAsset was deprecated - Use PHAsset from Photos Framework
我正在使用
检索图像
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) }
let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage
}
我可以检索图像,也可以使用图像输入按钮背景或我想要的任何其他内容,但我似乎无法检索照片的元数据。现在,在互联网上的其他各个位置有很多关于使用 ALAssets
及其图像数据技术的讨论,但是,ALAssets
最近已被弃用。由于我的图像不是用户刚刚拍摄的图像,而是从相机胶卷中选择的图像,因此我无法使用:
let metadata = info[UIImagePickerControllerMediaMetaData] as! NSDictionary
所以,如果有人能指出正确的方向,告诉我如何在不使用 ALAssets 的情况下获取用户刚刚从相机胶卷中挑选的图像的元数据,我将不胜感激!谢谢!
如果您想从相机胶卷中获取图像,那么这会有所帮助:
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let imageUrl = info["UIImagePickerControllerReferenceURL"]
let asset = PHAsset.fetchAssetsWithALAssetURLs([imageUrl], options: nil).firstObject as! PHAsset
print("location: " + String(asset.location))
print("Creation Date: " + String(asset.creationDate))
}
来自答案的Objective-C解决方案:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
NSString * imageUrl = info[@"UIImagePickerControllerReferenceURL"];
PHAsset * asset = [[PHAsset fetchAssetsWithALAssetURLs:[NSArray arrayWithObject:imageUrl] options:nil]firstObject];
NSLog(@"location: %@",asset.location);
NSLog(@"Creation Date: %@",asset.creationDate);
}
我正在使用
检索图像func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) }
let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage
}
我可以检索图像,也可以使用图像输入按钮背景或我想要的任何其他内容,但我似乎无法检索照片的元数据。现在,在互联网上的其他各个位置有很多关于使用 ALAssets
及其图像数据技术的讨论,但是,ALAssets
最近已被弃用。由于我的图像不是用户刚刚拍摄的图像,而是从相机胶卷中选择的图像,因此我无法使用:
let metadata = info[UIImagePickerControllerMediaMetaData] as! NSDictionary
所以,如果有人能指出正确的方向,告诉我如何在不使用 ALAssets 的情况下获取用户刚刚从相机胶卷中挑选的图像的元数据,我将不胜感激!谢谢!
如果您想从相机胶卷中获取图像,那么这会有所帮助:
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let imageUrl = info["UIImagePickerControllerReferenceURL"]
let asset = PHAsset.fetchAssetsWithALAssetURLs([imageUrl], options: nil).firstObject as! PHAsset
print("location: " + String(asset.location))
print("Creation Date: " + String(asset.creationDate))
}
来自
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
NSString * imageUrl = info[@"UIImagePickerControllerReferenceURL"];
PHAsset * asset = [[PHAsset fetchAssetsWithALAssetURLs:[NSArray arrayWithObject:imageUrl] options:nil]firstObject];
NSLog(@"location: %@",asset.location);
NSLog(@"Creation Date: %@",asset.creationDate);
}