attach a local video using UIActivityViewController

ijason03 picture ijason03 · Dec 23, 2012 · Viewed 9.9k times · Source

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];
}

Answer

RawMean picture RawMean · May 22, 2016

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)
}