Swift – 如何获取iPhone上的所有照片和video列表?

我希望能够查看存储在用户iPhone上的照片和video列表,以便我们允许他们select要上传的文件。 到目前为止,我已经在列表中显示照片的地方工作,但没有显示任何video。 我用来显示照片库的代码如下:

@IBAction func btnAddPicOrVideo(sender: AnyObject) { let pickerC = UIImagePickerController() pickerC.delegate = self self.presentViewController(pickerC, animated: true, completion: nil) } 

正如我所提到的,我可以显示照片列表,并select其中一个很好。 问题是我无法看到或select任何video。 有没有办法指定要显示的图片和video? 或者,我必须分别显示图片和video吗?

我目前正在模拟器上运行我的代码,并在本地存储了一个video文件。

提前致谢。

我能通过指定来解决这个问题

 import MobileCoreServices 

我改变了我上面指定的代码:

 @IBAction func btnAddPicOrVideo(sender: AnyObject) { let pickerC = UIImagePickerController() pickerC.mediaTypes = [kUTTypeImage as NSString, kUTTypeMovie as NSString] pickerC.delegate = self self.presentViewController(pickerC, animated: true, completion: nil) } 
 class ScoutDetailPage: UIViewController,UIImagePickerControllerDelegate { var picker:UIImagePickerController? = UIImagePickerController() let imageView = UIImageView () { override func viewDidLoad(){ // Do any additional setup after loading the view. self.loadOrTakePhotos() } func loadOrTakePhotos() { if(UIImagePickerController .isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)) { picker!.sourceType = UIImagePickerControllerSourceType.Camera picker?.delegate = self self .presentViewController(picker!, animated: true, completion: nil) } } else if (pickersegment.selectedSegmentIndex == 1) { picker!.sourceType = UIImagePickerControllerSourceType.PhotoLibrary picker?.delegate = self self.presentViewController(picker!, animated: true, completion: nil) } } func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) { let pickedimage = info[UIImagePickerControllerOriginalImage] as! UIImage imageView.image = pickedimage if (imageView.image != nil) { print("image not empty") // Do something here. picker .dismissViewControllerAnimated(false, completion: nil) } else { print("IMAGE VIEW NIL") } } func image(image: UIImage, didFinishSavingWithError error: NSErrorPointer, contextInfo:UnsafePointer<Void>) { if error != nil { let alert = UIAlertController(title: "Save Failed", message: "Failed to save image", preferredStyle: UIAlertControllerStyle.Alert) let cancelAction = UIAlertAction(title: "OK", style: .Cancel, handler: nil) alert.addAction(cancelAction) self.presentViewController(alert, animated: true, completion: nil) } } }