Reputation: 5914
I am trying to share videos from my app using a UIActivityViewController. Below is the code I use:
var url = NSURL(string: path!)!
var activityViewController = UIActivityViewController(activityItems: [url], applicationActivities: nil)
self.presentViewController(activityViewController, animated: true, completion: { () -> Void in })
The path points to a valid .mov file so no problems there. When I present the activity view controller I get the error: Unknown activity items supplied with the path to the .mov file and the sharing options only show AirDrop.
The app is running on iOS 8.
Any ideas?
EDIT I found out that when I save the video to camera roll. the user can share it with Photos app to any app. So there's nothing wrong with the video format I guess.
Upvotes: 1
Views: 770
Reputation: 978
I had a similar issue for a zip file and realised the url path I was passing was relative and not an absolute path. In other words, UIActivityViewController urls require the prefix file:///
I was using a relative path because the third party library Objective-Zip needs a relative path to create zip files.
Works:
file:///
private/var/mobile/Containers/Data/Application/63284C22-6E22-4865-965C-3B67F58D0659/tmp/myfile.zip
Doesn't work: /private/var/mobile/Containers/Data/Application/63284C22-6E22-4865-965C-3B67F58D0659/tmp/myfile.zip
Upvotes: 0
Reputation: 13766
You should use init?(fileURLWithPath path: String, isDirectory isDir: Bool)
if the movie is in resource bundle.
If you use imagePicker controller to select the video, you can get the url from info dictionary using the key UIImagePickerControllerMediaURL
, the corresponding delegate method is didFinishPickingMediaWithInfo
.
Upvotes: 1
Reputation: 209
Try this :
var activityViewController = UIActivityViewController(activityItems: [path], applicationActivities: nil)
self.presentViewController(activityViewController, animated: true, completion: { () -> Void in })
Upvotes: 0