Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIimagepicker controller image only selection

I have to give functionality to select photos by the user. I have used this:

ipc.sourceType =  UIImagePickerControllerSourceTypePhotoLibrary;

Now I have to restrict user to select only photos and i want videos to be not displayed on the list. Or somehow user should not select video at all. How to achieve that?

like image 372
Ankit Avatar asked Oct 07 '10 05:10

Ankit


2 Answers

basically what you're trying to do is to set the "media types". and luckily for you imagePicker has a property just for that called "mediaTypes". :) which receives an array of media types to show for selection.

even luckily-er this is the default behaviour of ImagePicker is to show only image types.

but if you really want to make sure you can do this:

[imagePicker setMediaTypes: [NSArray arrayWithObject:kUTTypeImage]];

and don't forget to add at the top of the file... :)

#import <MobileCoreServices/UTCoreTypes.h>

but really, i think we can trust apple when they say it's they're default behavior... :)

like image 196
Alex Zak Avatar answered Sep 23 '22 17:09

Alex Zak


You will get a compiler warning about incompatible pointer types (at least in XCode 4) when adding kUTTypeImage to an NSArray. However, kUTTypeImage is a CFStringRef, and according to the CFString documentation, a CFStringRef is compatible with NSString *. Therefore, to make the compiler happy, cast kUTTypeImage to an NSString *:

picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
like image 24
Jeremy Brooks Avatar answered Sep 23 '22 17:09

Jeremy Brooks