xcode 在 iOS 中打开带有视频和照片的图库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12165761/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:21:34  来源:igfitidea点击:

open gallery with videos AND photos in iOS

iosxcodeuiimagepickercontroller

提问by Jo?o Victor

I was using the UIImagePickerViewController, and i wanted to open the camera roll. But, in my app, i have a button to open my camera roll and another one to open my camera. When i take a picture or record a video, obviously i wanted to see those images in my camera roll. But, in my app, when i start to record a video, he doesn't show up in my camera roll's app.

我正在使用 UIImagePickerViewController,我想打开相机胶卷。但是,在我的应用程序中,我有一个按钮可以打开我的相机胶卷,另一个可以打开我的相机。当我拍照或录制视频时,显然我想在我的相机胶卷中看到这些图像。但是,在我的应用程序中,当我开始录制视频时,他没有出现在我的相机胶卷应用程序中。

Here's a little bit of code:

这里有一些代码:

UIImagePickerController *cameraRoll = [[UIImagePickerController alloc] init];

[cameraRoll setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];

[cameraRoll setDelegate:self];
[self presentModalViewController:cameraRoll animated:YES];

At this time i can't see my videos in my camera roll's app. Could someone help me?

目前我无法在相机胶卷的应用程序中看到我的视频。有人可以帮助我吗?

回答by Luis Ascorbe

You just can do like this:

你可以这样做:

if([UIImagePickerController isSourceTypeAvailable:
                        UIImagePickerControllerSourceTypePhotoLibrary]) {

     UIImagePickerController *picker= [[UIImagePickerController alloc] init];
     picker.delegate = self;
     picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
     picker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, (NSString *)kUTTypeImage, nil];

     [self presentModalViewController:picker animated:YES];
}

Sets the file types you want to get on the property of the PickerViewControllerObject "mediaTypes" and you're ready.

在 PickerViewControllerObject "mediaTypes" 的属性上设置您想要获取的文件类型,然后您就准备好了。

You can found the docs types here.

您可以在此处找到文档类型

Regards, Luis

问候, 路易斯