//创建
UIImagePickerController *imagePick = [[UIImagePickerController alloc] init];
imagePick.delegate = self;
imagePick.allowsEditing = YES;
imagePick.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePick.mediaTypes=[NSArray arrayWithObject:@"public.image"];
[self presentViewController:imagePick animated:animated completion:completion];
只需实现代理方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// get the ref url
NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:assetURL resultBlock:^(ALAsset *asset) {
ALAssetRepresentation *imageRep = [asset defaultRepresentation];
NSLog(@"[imageRep filename] : %@", [imageRep url]);
NSLog(@"[imageRep filename] : %@", [imageRep filename]);
} failureBlock:^(NSError *error) {
}];
}