Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

attach a local video using UIActivityViewController

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];
}
like image 397
ijason03 Avatar asked Dec 23 '12 04:12

ijason03


3 Answers

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)
}
like image 66
RawMean Avatar answered Nov 15 '22 18:11

RawMean


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.

like image 24
LeoSarena Avatar answered Nov 15 '22 16:11

LeoSarena


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

like image 37
Daij-Djan Avatar answered Nov 15 '22 16:11

Daij-Djan