您的位置:首页 > 移动开发 > IOS开发

iOS中获取相册中图片的文件名

2014-02-21 16:36 323 查看
原文地址:http://blog.liming.it/?p=90

第一步:给项目的 TARGETS -> Build Phases -> Link Binary With Libraries 增加框架链接 AssetsLibrary.Framework

第二步:文件中引入:

#import <AssetsLibrary/AssetsLibrary.h>

第三步:相册选择图片的回调方法 imagePickerController:didFinishPickingMediaWithInfo: 中,增加如下代码:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info;

{

// get the ref url

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

NSLog(@"[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];


...

}

[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: