Hi
I am getting a problem in load images from the gallery to UIImageView
in Xcode 5.
When I am trying to get images from the Gallery in UIImage
it will generate exceptional error in my screen.
Hi
I am getting a problem in load images from the gallery to UIImageView
in Xcode 5.
When I am trying to get images from the Gallery in UIImage
it will generate exceptional error in my screen.
You can use following method to load image from gallery.
You have to call methodToCallPhotos
when you click on gallery button.
-(void)methodToCallPhotos
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate = self;
[self presentModalViewController:imagePicker animated:YES];
}
After this when you select any image from the gallery. It calls delegate method like below
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
imageView.image = image;
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
First of all check if your app is granted permission to access Photo gallery.
Have a look at the documentation for ALAssetsLibrary here. To access all photos and videos you need to enumerate all groups (albums) in the photo library and then enumerate all photos and images in each group.
ALAssetsLibrary *al = [[ALAssetsLibrary alloc] init];
[al enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:^(ALAssetsGroup *group, BOOL *stop)
{
[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop)
{
if (asset)
{
.. do something with the asset
}
}
}
failureBlock:^(NSError *error)
{
.. handle error
}
];