我正在尝试在 iPad 上打开电影图库,但出现此错误,而且我不知道为什么。
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Source type must be UIImagePickerControllerSourceTypeCamera'
这是我的代码:
func GaleriaVideo() {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum) {
println("Galeria Video")
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum
imagePicker.mediaTypes = [kUTTypeMovie]
imagePicker.allowsEditing = false
imagePicker.showsCameraControls = false
imagePicker.modalPresentationStyle = .Custom
self.presentViewController(self.imagePicker, animated: true, completion: nil)
}
}
类似的代码适用于我的照片库,但我不知道为什么这不起作用。
你能告诉我我的代码有什么问题,或者我必须搜索什么才能做到这一点吗?几天前我正在尝试这个,但我感到迷失了。
谢谢你,
编辑:
这是我的照片库,它可以正常工作:
func GaleriaImagen() {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum){
println("Galeria Imagen")
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum
imagePicker.allowsEditing = false
imagePicker.modalPresentationStyle = .Custom
self.presentViewController(self.imagePicker, animated: true, completion: nil)
}
}
func imagePickerControllerDidCancel(picker: UIImagePickerController!) {
self.dismissViewControllerAnimated(false, completion: nil)
}
func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: NSDictionary!) {
self.dismissViewControllerAnimated(true, completion: nil)
}
最佳答案
试试这个
func GaleriaVideo() {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum) {
println("Galeria Video")
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
imagePicker.mediaTypes = [kUTTypeMovie]
imagePicker.allowsEditing = false
imagePicker.showsCameraControls = false
imagePicker.modalPresentationStyle = .Custom
self.presentViewController(self.imagePicker, animated: true, completion: nil)
}
}
关于ios - 如何快速打开电影画廊,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29276298/