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];
}
Stan James
  • 2,535
  • 1
  • 28
  • 35
ijason03
  • 571
  • 2
  • 9
  • 26

3 Answers3

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)
}
RawMean
  • 8,374
  • 6
  • 55
  • 82
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://stackoverflow.com/a/20211603/2074320 for your information.

Community
  • 1
  • 1
LeoSarena
  • 189
  • 2
  • 8
1

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

Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
  • 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? – ijason03 Dec 24 '12 at 04:25
  • I've tried using SLComposeViewController instead of UIActivityViewController. Using SLComposeViewController, the file link gets posted but not the actual file. file://...output.mp4 – ijason03 Dec 24 '12 at 05:01
  • Any code showing how to post videos using iOS7 and the UIActivityViewController? – C0D3 Sep 08 '14 at 15:49
  • can anyone share a code, any code to share video file, from example from s3 to facebook using UIActivityViewController – user3728728 Aug 15 '15 at 12:23