iOS 从相册中拿到 图片名 ,截取后缀,图片名
//从路径中获得完整的文件名 (带后缀) 对从相册中取出的图片,视频都有效。
NSString *fileName = [filePath lastPathComponent];
//获得文件名 (不带后缀)
NSString *fileName1 = [filePath stringByDeletingPathExtension];
//获得文件的后缀名 (不带'.')
NSString *suffix = [filePath pathExtension];
// 拿到图片名字 亲测只对图片有效
NSURL *refURL = [info valueForKey:UIImagePickerControllerReferenceURL];
define the block to call when we get the asset based on the url (below)
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *imageAsset)
{
ALAssetRepresentation *imageRep = [imageAsset defaultRepresentation];
DNLog(@"[imageRep filename] : %@", [imageRep filename]);
};
// get the asset library and fetch the asset based on the ref url (pass in block above)
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:refURL resultBlock:resultblock failureBlock:nil];
[picker dismissViewControllerAnimated:YES completion:nil];
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步