【问题标题】:how to share video in twitter with UIActivityViewController如何使用 UIActivityViewController 在 Twitter 中分享视频
【发布时间】:2015-12-30 02:47:42
【问题描述】:

当我使用 UIActivityViewController 分享视频时,推特帖子不显示视频。但是,如果它使用 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 消息发送视频很好)。

【问题讨论】:

  • 请参考此链接,它可能对您有所帮助:stackoverflow.com/questions/30612386/…
  • 那么是不是不能使用UIActivityViewController(iOS内置框架)?
  • 我给你的以上链接对于在推特上分享视频很有用,请通过它。

标签: ios video twitter


【解决方案1】:

视频无法与 UIActivityViewController 共享。

感谢the uploading media new API,您可以通过它分享视频到推特。而且我试过了,效果很好。

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

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

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

【讨论】:

    【解决方案2】:

    试试这个:

    + (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."];
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-18
      • 1970-01-01
      • 2018-03-21
      • 2016-10-29
      • 1970-01-01
      相关资源
      最近更新 更多