how to show only images without showing videos when choose photo button is tapped in iPhone app

ios, objective-c, uiimagepickercontroller

Solution

You need to use the mediaTypes property:

controller.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeImage, nil];

Reference:

mediaTypes

An array indicating the media types to be accessed by the media picker controller.

`@property (nonatomic, copy) NSArray *mediaTypes`

Discussion

Depending on the media types you assign to this property, the picker displays a dedicated interface for still images or movies, or a selection control that lets the user choose the picker interface. Before setting this property, check which media types are available by calling the `availableMediaTypesForSourceType:` class method.

If you set this property to an empty array, or to an array in which none of the media types is available for the current source, the system throws an exception.

When capturing media, the value of this property determines the camera interface to display. When browsing saved media, this property determines the types of media presented in the interface.

By default, this property is set to the single value `kUTTypeImage`, which designates the still camera interface when capturing media, and specifies that only still images should be displayed in the media picker when browsing saved media. To designate the movie capture interface, or to indicate that only movies should be displayed when browsing saved media, use the `kUTTypeMovie` identifier in a statement like this:

`myImagePickerController.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];`

To designate all available media types for a source, use a statement like this:

`myImagePickerController.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType: UIImagePickerControllerSourceTypeCamera];`

Problem

In my app a choose photo button is there,when tapped on the button it should take to iPhone photos and show only images without showing videos present.With my code its showing images as well as videos.What could be the way to show only images.looking for help,thanks in advanace.Below is my code: ``` #import <AssetsLibrary/AssetsLibrary.h> -(void)choosePhotoFromExistingImages { if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary]) { controller = [[UIImagePickerController alloc] init]; controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; controller.allowsEditing = NO; controller.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType: UIImagePickerControllerSourceTypePhotoLibrary]; controller.delegate = self; [self.navigationController presentViewController: controller animated: YES completion: nil]; } ``` } ``` -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { if (picker==controller){ [self.navigationController dismissViewControllerAnimated: YES completion: nil]; UIImage *image1 = [info valueForKey: UIImagePickerControllerOriginalImage]; CGFloat compression = 0.9f; CGFloat maxCompression = 0.1f; int maxFileSize = 250*1024; NSData *imageData = UIImageJPEGRepresentation(image1, compression); while ([imageData length] > maxFileSize && compression > maxCompression) { compression -= 0.1; imageData = UIImageJPEGRepresentation(image1, compression); } imgVwProfile.image=image1; // 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]; // strProileImg=[imageRep filename]; ALAssetRepresentation *imageRep=[imageAsset defaultRepresentation]; strProfileImg = [imageRep filename]; NSLog(@"%@",strProfileImg); }; // 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]; } } ```

Original source