Question

I want to share videos from my application into youtube and instagram using UIActivityViewController. But i got output like below mentioned image.

enter image description here

But my Expectation is, to add Youtube and Instagram apps into this UIActivityViewController for Videos. Like below mentioned image. This image taken from device Photo album.

enter image description here

My Code is:

- (IBAction)ShareVideo:(id)sender
{
    NSString *mySubject=@"Video Sharing ";
    NSString *textLocationA=@"India";
    NSString *textObject = @"Video Sharing Test";
    NSData *videoData = [NSData dataWithContentsOfURL:movieURL]; //movieURL contains the video taken from photoAlbum

    NSArray *objectsToShare = @[mySubject,textLocationA,textObject,videoData,movieURL];

    UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];

    // Exclude all activities except AirDrop.
    NSArray *excludedActivities = @[UIActivityTypePostToTwitter, UIActivityTypePostToFacebook,
                                    UIActivityTypePostToWeibo,
                                    UIActivityTypeMessage, UIActivityTypeMail,
                                    UIActivityTypePrint, UIActivityTypeCopyToPasteboard,
                                    UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll,
                                    UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr,
                                    UIActivityTypePostToVimeo, UIActivityTypePostToTencentWeibo];
    controller.excludedActivityTypes = excludedActivities;

    //-- define the activity view completion handler
    controller.completionHandler = ^(NSString *activityType, BOOL completed){
        NSLog(@"Activity Type selected: %@", activityType);
        if (completed) {
            NSLog(@"Selected activity was performed.");
        } else {
            if (activityType == NULL) {
                NSLog(@"User dismissed the view controller without making a selection.");
            } else {
                NSLog(@"Activity was not performed.");
            }
        }
    };

    //-- define activity to be excluded (if any)
    controller.excludedActivityTypes = [NSArray arrayWithObjects:UIActivityTypeAssignToContact, nil];
    [controller setCompletionHandler:^(NSString *activityType, BOOL completed) {
        if ([activityType isEqualToString:UIActivityTypePostToFacebook]) {
            if (completed)
            {
                NSLog(@"facebook");

            }

        }
        else if ([activityType isEqualToString:UIActivityTypeSaveToCameraRoll]) {
            if (completed)
            {
                NSLog(@"Video Saved");
            }
        }

        else if ([activityType isEqualToString:UIActivityTypePostToTwitter]) {
            if (completed)
            {
                NSLog(@"twittter");
            }

        }
    }];

    // Present the controller
    [self presentViewController:controller animated:YES completion:nil];
}

Please give me some idea to handle this process.

Was it helpful?

OTHER TIPS

To add YouTube in UIActivityViewController, you have to custom the UIActivityViewController by yourself. Please refer How can I create a custom UIActivity in iOS? I added a custom Youtube icon in the UIActivityViewController and enable to upload video to Youtube.

For how to upload video to YouTube, you can read this https://nsrover.wordpress.com/2014/04/23/youtube-api-on-ios/ I tested it. It works.

  1. You have to add your own custom UIActivity for youtube: How can I create a custom UIActivity in iOS?
  2. Add share dialog. You can use this lib: https://github.com/romaonthego/REComposeViewController
  3. Use API for sharing. Thanks @UserAwesome : http://code.google.com/apis/youtube/2.0/developers_guide_protocol.html#Uploading_Videos

OR

You can try to find existing component for it. :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top