gpt4 book ai didi

ios - 我如何在没有 ALAssetsLibrary 的情况下从 "UIImagePickerControllerReferenceURL"获取 UIImage

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:06:46 50 4
gpt4 key购买 nike

<分区>

-(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);
}];
}

50 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com