-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
NSURL *url = [info objectForKey:@"UIImagePickerControllerReferenceURL"];
NSLog(@"url : %@",url);
}
我知道我们总是使用ALAssetsLibrary通过UIImagePickerControllerReferenceURL获取UIIMage。但它已被弃用,我还有其他方式吗?
顺便说一下,代码的输出如下:
assets-library://asset/asset.JPG?id=106E99A1-4F6A-45A2-B320-B0AD4A8E8473&ext=JPG
我检查了苹果官方文档,发现ALAssetsLibrary被PHPhotoLibrary取代。
我的天啊!最后我发现,这是答案:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
NSURL *url = [info objectForKey:UIImagePickerControllerReferenceURL];
PHFetchResult *result = [PHAsset fetchAssetsWithALAssetURLs:@[url] options:nil];
PHAsset *asset = result.firstObject;
PHImageManager *manager = [PHImageManager defaultManager];
[manager requestImageForAsset:asset targetSize:CGSizeMake(100, 100) contentMode:PHImageContentModeAspectFit options:nil resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
NSLog(@"%@",result);
}];
}