我希望能够查看存储在用户的iPhone照片和视频的列表,以便我可以让他们选择要上传的文件。 到目前为止,我有工作在那里的照片在列表中显示出来,但没有视频被显示出来。 我使用的显示照片库中的代码如下:
@IBAction func btnAddPicOrVideo(sender: AnyObject) {
let pickerC = UIImagePickerController()
pickerC.delegate = self
self.presentViewController(pickerC, animated: true, completion: nil)
}
正如我所说的,我能够显示照片列表,并选择其中一个就好了。 问题是,我无法看到或选择任何视频。 是否有指定两个图片和视频要显示的方式吗? 或者,我必须分别显示照片和录像?
我目前正在运行的我在模拟器上的代码,我有一个视频文件存储在本地。
提前致谢。
我能得到这个指定解析
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)
}
}
}