相册获取照片时,同时获取照片名称
2016-02-07 03:42
363 查看
首先我们要添加AssetsLibrary库
#import <AssetsLibrary/AssetsLibrary.h>
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. [self setTitle:[AppDelegate appDelegate].mainListDataSource[2]]; self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:[[UIBarButtonItem alloc]initWithTitle:@"相册" style:UIBarButtonItemStyleDone target:self action:@selector(pickPicture)], nil]; _showPicIMGV.layer.cornerRadius = 20; _showPicIMGV.layer.borderWidth = 1; _showPicIMGV.layer.masksToBounds = YES; } - (void)pickPicture { if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) { UIImagePickerController *imgPicker = [[UIImagePickerController alloc]init]; imgPicker.delegate = self; imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [self.navigationController presentViewController:imgPicker animated:YES completion:^{ }]; } } - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{ NSURL *imgUrl = [info objectForKey:UIImagePickerControllerReferenceURL]; ALAssetsLibraryAssetForURLResultBlock resultBlock = ^(ALAsset *myAsset){ ALAssetRepresentation *reprsentation = [myAsset defaultRepresentation]; imgName = [reprsentation filename]; UIImage *img = [info objectForKey:UIImagePickerControllerOriginalImage]; _showPicIMGV.image = img; [picker dismissViewControllerAnimated:YES completion:nil]; }; [[[ALAssetsLibrary alloc]init]assetForURL:imgUrl resultBlock:resultBlock failureBlock:nil]; }
相关文章推荐
- 测试·主打单元测试
- c语言:不用if,else语句,也不用循环条件等,输入一个字符,判断是否为大写字母
- 你所不知道的程序猿博客
- 51Nod 1065 最小正子段和(归并 贪心,好题)
- Mac os x 系统开启自带php环境
- C语言的STL 库
- C变异测试 mutation testing 工具 Milu
- Android中常用颜色值
- 51Nod 1050 循环数组最大子段和(dp)
- Mysql表的操作
- IntelliJ IDEA的Maven项目在修改时报java.lang.OutOfMemoryError: PermGen space异常
- 安卓界面延时跳转
- Intellij IDEA14 下添加ExtJS提示支持
- 在Qt for Android中添加.a或so库文件
- 文章标题
- RedHat安装jdk
- 使用基于Http的消息代替WebService的数据交互
- DNS,ARP,秘钥和数字签名.
- 在屏幕上滑动慢慢翻开表面的图片
- 用 Node JS 看糗百段子