attach a local video using UIActivityViewController
Asked Answered
A

3

11

I'm writing an iOS app that has locally saved videos (.mov). I'm trying to attach the video via UIActivityViewController. It works great for email. The video is successfully attached and sent. It also works when saving to camera roll.
It doesn't work when attaching to Messages. Only the text is shown. Also Twitter and Facebook do not even show up. When I remove the video attachment, Twitter and Facebook finally begin to show. I don't really care too much about Messages but can anyone tell me why Facebook and Twitter are not showing up?

Heres my code:

- (IBAction) shareVideo {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *URL = [documentsDirectory stringByAppendingPathComponent:demoName];

    NSString* someText = demoName;
    NSURL *urlToShare = [NSURL fileURLWithPath:URL isDirectory:NO];
    NSArray* dataToShare = @[someText, urlToShare];

    UIActivityViewController* activityViewController =
    [[UIActivityViewController alloc] initWithActivityItems:dataToShare
                                      applicationActivities:nil];
    activityViewController.excludedActivityTypes = @[UIActivityTypePrint,UIActivityTypeCopyToPasteboard,UIActivityTypeAssignToContact];

    activityViewController.completionHandler = ^(NSString *activityType, BOOL completed) {
        //if (completed) {
        [self dismissViewControllerAnimated:YES completion:nil];
        //}
    };

    [self presentViewController:activityViewController animated:YES completion:nil];
}
Armour answered 23/12, 2012 at 4:57 Comment(0)
T
4

You cannot share videos on Facebook, twitter or on sms in iOS 6 or below. It's only available in iOS7.

Also, please check https://mcmap.net/q/1018043/-uiactivitycontroller-behaviour-different-on-device-and-simulator for your information.

Trixi answered 26/11, 2013 at 9:24 Comment(1)
Any code showing how to post videos using iOS7 and the UIActivityViewController?Tallow
R
8

The other answers are outdated. This works:

    @IBAction func didTapShare(sender: AnyObject) {
    let videoURL = NSURL(fileURLWithPath:localVideoPath)
    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)
}
Requiem answered 22/5, 2016 at 6:19 Comment(2)
how to play mp4 video in different apps (call them from my app)?Nalley
I cannot make this working along with text. It's always sharing the text or the video.Kingofarms
T
4

You cannot share videos on Facebook, twitter or on sms in iOS 6 or below. It's only available in iOS7.

Also, please check https://mcmap.net/q/1018043/-uiactivitycontroller-behaviour-different-on-device-and-simulator for your information.

Trixi answered 26/11, 2013 at 9:24 Comment(1)
Any code showing how to post videos using iOS7 and the UIActivityViewController?Tallow
D
1

they are hidden because you cannot display movs on fb twitter or in sms

Dex answered 23/12, 2012 at 9:11 Comment(4)
I'm now saving my files as mp4 instead of mov. Still no Facebook or twitter. The files are small about 10 seconds long. Any ideas?Armour
I've tried using SLComposeViewController instead of UIActivityViewController. Using SLComposeViewController, the file link gets posted but not the actual file. file://...output.mp4Armour
Any code showing how to post videos using iOS7 and the UIActivityViewController?Tallow
can anyone share a code, any code to share video file, from example from s3 to facebook using UIActivityViewControllerSafar

© 2022 - 2024 — McMap. All rights reserved.