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];

        }

    }
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM