将视频分享到Facebook - Swift IOS

时间:2016-05-28 17:21:18

标签: ios swift facebook

我正在编写应用以尝试将视频发布到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
    }

1 个答案:

答案 0 :(得分:0)

  1. 仅限照片问题
  2. 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)
        }
    }
    
    1. 对于第二个问题,您应该先检查网址
    2. 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
        }
      }