使用UIActivityViewController分享视频 - 对于Facebook有效,但对于YouTube无效。

3
我正在使用原生iOS共享表单,它可以用于所有东西:邮件、照片、Facebook。除了YouTube之外的所有内容。我尝试了.mov和.mp4扩展名以及不同大小的文件。
更新。
视频共享表单也不显示Twitter选项。这也适用于照片或相机。然而,照片的共享表单显示YouTube图标,这告诉我我做错了什么。
图像显示具有白色共享表单的iOS应用程序。有许多图标:邮件、Facebook、保存视频,但没有Twitter或YouTube
此状态栏是在Altershot中编辑的
NSData *urlData = [NSData dataWithContentsOfURL:urlToDownload];
if (urlData) {
    // File downloaded

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString  *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"file.mov"];
    [urlData writeToFile:filePath atomically:YES];
    // File saved

    NSURL *videoLink = [NSURL fileURLWithPath:filePath];
    NSArray *activityItems = @[videoLink];
    UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
    [activityViewController setValue:@"Video" forKey:@"subject"];

    if (IS_IPAD) {
        self.popover = [[UIPopoverController alloc]
                        initWithContentViewController:activityViewController];
        [self.popover presentPopoverFromRect:self.shareButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
    } else {
        [self presentViewController:activityViewController animated:YES completion:nil];
    }
}

你知道在YouTube上分享视频不是开箱即用的,对吧? - Jasper
@Jasper 谢谢,我不知道这个。那为什么它在照片上能工作,如何让它与本地工具一起工作? - Boris Y.
你的意思是在Photos.app中查看一张随机照片,然后按分享按钮,就会显示分享到YouTube的选项吗?我没有这个选项(但已安装了YouTube.app)。 - Jasper
@Jasper 不,我只是在谈论视频。 - Boris Y.
当然,我也可以为视频选择这个选项。但是,我认为您不能期望从自己创建的应用程序中获得相同的基本功能。 - Jasper
保存视频选项是如何出现的?我没有看到这个选项。 - Mihir Oza
1个回答

2
据我所知,直接共享到YouTube是不支持的。
如果您希望将“YouTube”选项添加到您的“UIActivityViewController”中,则需要创建自定义“UIActivity”。
简单实现:
//  YouTubeActivity.h
#import <UIKit/UIKit.h>

@interface YouTubeActivity : UIActivity

@end


//  YouTubeActivity.m

#import "YouTubeActivity.h"
//You might need to import some YouTube framework too

@interface YouTubeActivity ()

@end

@implementation YouTubeActivity

- (NSString *)activityType
{
    return @"YouTube";
}

- (NSString *)activityTitle
{
    return @"YouTube";
}

- (UIImage *)_activityImage
{
    return [UIImage imageNamed:@"some_youtube_image"];
}

- (BOOL)canPerformWithActivityItems:(NSArray *)activityItems
{
    return YES;
}

- (void)prepareWithActivityItems:(NSArray *)activityItems
{

}

- (UIViewController *)activityViewController
{
    return nil;
}

- (void)performActivity
{
    // This is where you can do anything you want, and is the whole reason for creating a custom
    // UIActivity

}

@end

创建UIActivityViewController时,您需要将一个初始化的YouTubeActivity对象添加到您的activityItems中。

请查看YouTube API文档,了解分享功能的实际实现。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接