if ([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController* imagePicker;
imagePicker = [[UIImagePickerControlleralloc]init];
imagePicker.delegate =self;
imagePicker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [UIImagePickerControlleravailableMediaTypesForSourceType:imagePicker.sourceType];
imagePicker.navigationBar.barTintColor = [selfviewController].navigationController.navigationBar.barTintColor;
[[selfviewController]presentViewController:imagePickeranimated:YEScompletion:nil];
}
//delegate
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [infoobjectForKey:UIImagePickerControllerOriginalImage];
if (image !=nil) {
//获取图片的名字
__blockNSString* imageFileName;
NSURL *imageURL = [infovalueForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *representation = [myassetdefaultRepresentation];
imageFileName = [representation filename];
};
ALAssetsLibrary* assetslibrary = [[ALAssetsLibraryalloc] init];
[assetslibrary assetForURL:imageURL
resultBlock:resultblock
failureBlock:nil];
[picker dismissViewControllerAnimated:truecompletion:nil];
}
}
IOS技术交流群:129582174