Using UIActivityViewController to share a video

社会主义新天地 提交于 2019-12-06 08:15:35

问题


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

回答1:


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.




回答2:


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)



回答3:


If you are using an avasset, you can get the url using (AVUrlAsset*)AVAsset.url



来源:https://stackoverflow.com/questions/19992842/using-uiactivityviewcontroller-to-share-a-video

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!