我正在编写应用以尝试将视频发布到Facebook。理想情况下,我想从Parse中提取视频,并将其转换为NSURL。现在我正在尝试使用ImagePicker来挑选用于分享的照片。
现在我已经出现了ImagePicker,但我收到了两个错误。 1)只有照片显示在卷筒中,2)我在展开时找到了nil可选值'在我的didFinishPickingMediaWithInfo函数中。对于问题1,我已将UIImagePickerControllerSourceType更改为.PhotoLibrary,但它仍然省略了视频。
override func viewWillAppear(animated: Bool) {
let profileButton = UIBarButtonItem(image: img, style: .Done, target: self, action: "videoBtnClicked")
self.navigationItem.setRightBarButtonItem(profileButton, animated: true)
func videoBtnClicked(){
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum){
print("Video capture")
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum
imagePicker.allowsEditing = false
self.presentViewController(imagePicker, animated: true, completion: nil)
}
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let video : FBSDKShareVideo = FBSDKShareVideo()
//error occurs line below here
video.videoURL = info[UIImagePickerControllerMediaURL] as! NSURL
let content : FBSDKShareVideoContent = FBSDKShareVideoContent()
content.video = video
}
答案 0 :(得分:0)
func videoBtnClicked(){ if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum){ print("Video capture") imagePicker.delegate = self imagePicker.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum **imagePicker.mediaTypes = ["public.movie"]** imagePicker.allowsEditing = false self.presentViewController(imagePicker, animated: true, completion: nil) } }
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { let video : FBSDKShareVideo = FBSDKShareVideo() //error occurs line below here if let url = video.videoURL{ video.videoURL = info[UIImagePickerControllerMediaURL] as? NSURL let content : FBSDKShareVideoContent = FBSDKShareVideoContent() content.video = video } }