iOS 使用系统相册获取选取图片的名称

编程入门 行业动态 更新时间:2024-10-27 06:32:40

iOS 使用系统相册获取选取图片的<a href=https://www.elefans.com/category/jswz/34/1771109.html style=名称"/>

iOS 使用系统相册获取选取图片的名称

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];//1.选择的是图片资源if ([mediaType isEqualToString:@"public.image"]) {

      if (img !=nil) {

            //获取图片的名字

            __block NSString* imageFileName;

            NSURL *imageURL = [info valueForKey:UIImagePickerControllerReferenceURL];

            NSLog(@"imgurl:%@",imageURL);

            __weak typeof(self) weakSelf = self;

            ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)

            {

                ALAssetRepresentation *representation = [myasset defaultRepresentation];

                imageFileName = [representation filename];

            };

            ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];

            [assetslibrary assetForURL:imageURL

                           resultBlock:resultblock

                          failureBlock:nil];

        }

    }
}

转载于:.html

更多推荐

iOS 使用系统相册获取选取图片的名称

本文发布于:2023-07-01 07:48:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/972829.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:名称   相册   系统   图片   iOS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!