Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using UIActivityViewController to share a video

I am trying to use the default apple share screen to share a video to things like twitter and facebook. I have got this to work with an image but I do not know how change this to work with a video. Thanks in advance!

Here is the code I am using to share the photo:

(IBAction)shareButtonPressed:(id)sender {

    UIImage *imagetoshare = [UIImage imageNamed:@"First_Time_Travel"];
    NSArray *activityItems = @[imagetoshare];
    UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
    activityVC.excludedActivityTypes = @[UIActivityTypeAssignToContact, UIActivityTypePrint];
    [self presentViewController:activityVC animated:TRUE completion:nil];
}
like image 433
matthewmoss Avatar asked Oct 20 '25 04:10

matthewmoss


2 Answers

You need a file URL to the video file or and ALAsset representing the video. Use either of those as the object in your activityItems array.

like image 111
rmaddy Avatar answered Oct 22 '25 17:10

rmaddy


For swift 3.0 OR up

let url = URL(fileURLWithPath: "URL String Here")
let activityViewController = UIActivityViewController(activityItems: [url], applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = controller.view // so that iPads won't crash
controller.present(activityViewController, animated: true, completion: nil)
like image 30
Hiren Panchal Avatar answered Oct 22 '25 18:10

Hiren Panchal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!