3

I am using the native iOS share sheet and it works for everything: Mail, Photos, Facebook. Everything except YouTube. I tried .mov and .mp4 extensions and files with different size.

Update.
The share sheet with video also doesn't display Twitter option. This is also true for the Photos or Camera. However, Photos' share sheet displays YouTube icon, this tells me that I'm doing something wrong.

Image displays iOS app with white share sheet. There's many icons: Mail, Facebook, save video, but not Twitter or YouTube
This status bar was edited in the 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];
    }
}
Boris Y.
  • 4,387
  • 2
  • 32
  • 50
  • You know that sharing on YouTube does not work out of the box, right? – Jasper Sep 17 '15 at 12:52
  • @Jasper thanks, I didn't know that. Why it is working on Photos then and how make it work with native tools? – Boris Y. Sep 17 '15 at 12:53
  • You mean a random photo viewed in Photos.app, pressing the share button, shows you the YouTube option to share to? I don't have this option (but have the YouTube.app installed) – Jasper Sep 17 '15 at 12:55
  • @Jasper no, I am talking only about videos here. – Boris Y. Sep 17 '15 at 12:56
  • Oh, of course.. I do get that option too for video's. However, I don't think you can expect the same basic functionality from within your own created app. – Jasper Sep 17 '15 at 12:57
  • How save video option came? I am not getting this option – Mihir Oza Sep 20 '17 at 07:32

1 Answers1

2

As far as I know, sharing to YouTube does not work out-of-the-box.

You will need to create a custom UIActivity if you want to add the YouTube option to your UIActivityViewController.

Simple implementation:

//  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

You will have to add an initialised YouTubeActivity object to your activityItems when creating your UIActivityViewController

Check the YouTube API Documentation for the actual implementation of the share function.

Jasper
  • 7,031
  • 3
  • 35
  • 43