如何使用UIActivityViewController在twitter上分享视频

时间:2015-10-01 22:35:56

标签: ios video twitter

当我使用UIActivityViewController分享视频时,Twitter帖子不显示视频。但是,如果它使用相同的视频并使用Twitter应用发布,则视频会在帖子中显示和播放。

我正在使用此代码:

 MyActivityItemProvider * videoItem = [[MyActivityItemProvider alloc] initWithPlaceholderItem:@""];


    NSArray * activityItems = [NSArray arrayWithObjects:
                               videoItem,
                               nil];

    UIActivityViewController *activityViewController = [[UIActivityViewController alloc]
                                                        initWithActivityItems:activityItems
                                                        applicationActivities:nil];

    [self presentViewController:activityViewController animated:YES completion:nil];

在MyActivityItemProvider中,我有这个:

@implementation MyActivityItemProvider

- (MyActivityItemProvider * )initWithPlaceholderItem:(NSString *)placeholderItem
{
    self = [super initWithPlaceholderItem:placeholderItem];

    return self;
}
- (id)item
{
    NSString * path = [[NSBundle mainBundle] pathForResource:@"video_name" ofType:@"mp4"];

    NSURL * fileURL = [NSURL fileURLWithPath:path];

    return fileURL;
}

@end

使用UIActivityViewController发布时,Twitter视频帖子是否有可能将视频嵌入其中(就像我使用Twitter应用程序发布的那样)?关于如何实现这个(看起来像什么)相当简单的任务的任何建议?

视频是.mp4,它是3.1 MB(就像我说的,似乎使用Twitter应用程序发布很好,我可以通过txt消息发送视频)。

2 个答案:

答案 0 :(得分:1)

无法与UIActivityViewController共享视​​频。

感谢the uploading media new API,您可以通过它分享视频到Twitter。我尝试过它,它有效。

请检查:https://github.com/liu044100/SocialVideoHelper

你只需要调用这个类方法。

+(void)uploadTwitterVideo:(NSData*)videoData comment:(NSString*)comment account:(ACAccount*)account withCompletion:(VideoUploadCompletion)completion;

答案 1 :(得分:0)

试试这个:

+ (void)shareOnTwiiterFromView:(UIViewController *)vc userTitle:(NSString *)title shareURL:(NSString *)urlString
{
    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
    {
        SLComposeViewController *tweetSheet = [SLComposeViewController
                                               composeViewControllerForServiceType:
                                               SLServiceTypeTwitter];

        tweetSheet.completionHandler = ^(SLComposeViewControllerResult result)
        {
            switch(result)
            {
                case SLComposeViewControllerResultCancelled:
                    break;
                case SLComposeViewControllerResultDone:
                    break;
            }
        };

        NSString *twTitle = [NSString stringWithFormat:@"%@ %@",title,@"Your App Name"];
        [tweetSheet setInitialText:twTitle];

        if (![tweetSheet addURL:[NSURL URLWithString:urlString]])
        {
            NSLog(@"Unable to add the URL!");
        }

        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
        {
            UIPresentationController *control = tweetSheet.presentationController;
            [tweetSheet setModalPresentationStyle:UIModalPresentationFormSheet];

             [vc presentViewController:control.presentedViewController animated:YES completion:^
             {
                 NSLog(@"Tweet sheet has been presented.");
             }];
        }
        else
        {
             [vc presentViewController:tweetSheet animated:NO completion:^
             {
                 NSLog(@"Tweet sheet has been presented.");
             }];
        }
    }
    else
    {
        [APP_DEL showErrorAlert:@"No Twitter Account" description:@"There are no twitter accounts configured. You can add or create a Twitter account in Settings."];
    }
}