Reputation: 285
I want users to be able to use a camera but not have the option of taking a video. As it stands, both photo and video controls show in the bottom left corner of the view when camera is launched by user. Below are my launchCamera and imagePickerController methods.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
self.image = [info objectForKey:UIImagePickerControllerOriginalImage];
self.challengePic.image = self.image;
if (self.imagePicker.sourceType == UIImagePickerControllerSourceTypeCamera) {
UIImageWriteToSavedPhotosAlbum(self.image, nil, nil, nil);
self.challengePic.image = self.image;
}
[self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)launchCamera:(id)sender {
if (self.image == nil && [self.videoFilePath length] == 0) {
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.delegate = self;
self.imagePicker.allowsEditing = NO;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
else {
self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
self.imagePicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:self.imagePicker.sourceType];
[self presentViewController:self.imagePicker animated:NO completion:nil];
}
}
- (IBAction)launchAlbum:(id)sender {
if (self.image == nil && [self.videoFilePath length] == 0) {
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.delegate = self;
self.imagePicker.allowsEditing = NO;
self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
self.imagePicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:self.imagePicker.sourceType];
[self presentViewController:self.imagePicker animated:NO completion:nil];
}
}
Is there any way of setting the Image picker sourceType so that only pictures and no video can be selected? Thanks in advance!
Upvotes: 8
Views: 8118
Reputation: 123
If you only want to select images or videos, you can use a code like this.
self.imagePicker.mediaTypes = ["public.image"]
or
self.imagePicker.mediaTypes = ["public. movie"]
Upvotes: 1
Reputation: 318794
If you only want to select images, don't set the mediaTypes
property to all possible media types for the given source.
By default, the image picker will only show images from the photo library.
But your setting of mediaTypes
is overriding this default and allowing videos as well.
Upvotes: 13
Reputation: 15331
Don't include this line:
self.imagePicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:self.imagePicker.sourceType];
From the UIImagePickerController class Reference:
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….
Upvotes: 13