2017-08-23 16 views
2

私はアプリケーションを開発しており、uiactivityviewcontrollerを使用して画像ディレクトリに保存された画像のビデオやその他のファイルを共有したいと考えています。画像とファイルの共有が正しく機能しています。ドキュメントディレクトリに格納されている他のファイルに対してuiactivityViewcontrollerを使用してビデオを共有する

var textToShare : Any! 
textToShare = UIImage(data:data)//data of an image 

コードを共有するための画像 コード。

var textToShare : Any! 
textToShare = url//url of file saved into document directory 

しかし、ビデオの共有方法はわかりません。この後、私はactivityviewcontrollerを使用するために次のコードを使用しています。

let activityViewController = UIActivityViewController(activityItems: [textToShare], applicationActivities: nil) 
    activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash 

    // exclude some activity types from the list (optional) 
    activityViewController.excludedActivityTypes = [ UIActivityType.airDrop, UIActivityType.postToFacebook ] 

    // present the view controller 
    self.present(activityViewController, animated: true, completion: nil) 

答えて

3

まず、ビデオファイルのパスに

let videoURL = NSURL(fileURLWithPath:localVideoPath) 

を取得し、私はすでに動画のURLを持っていますが、それはローカルパスに格納されていない

let activityItems = [videoURL, "Check this out!" ] 
let activityController = UIActivityViewController(activityItems: activityItems, applicationActivities: nil) 

activityController.popoverPresentationController?.sourceView = self.view 
activityController.popoverPresentationController?.sourceRect = self.view.frame 

self.presentViewController(activityController, animated: true, completion: nil) 
+0

下回るようUIActivityViewControllerにこのパスを渡します。ギャラリーに保存されます。私はまずそれをエクスポートする必要があります。あなたはビデオをエクスポートする方法を説明できますか?私はすでにこれを試しましたが、ビデオを共有できません。 –

+2

はい、ギャラリーで提供されているパスを使用しても問題ありません。 UIImagePickerControllerを使用していますか? –

+0

いいえ、今私はギャラリーに格納されているすべてのビデオのURLを取得するためにファセットを使用しています。将来私はUiImagePickerControllerを切り替えることを考えていますが、今私はビデオのURLしか持っていませんし、私はそれをエクスポートしたいと思います。 URLだけを使ってエクスポートする方法がない場合は、私に知らせてください。 UiImagePickerControllerを使用するようにコードを変更します。 tahnk you :) –

関連する問題