Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share video from youtube app to my app on ios

Is there anyway I can get my app to appear when I click the share button on a video in the youtube app on ios?

I know how to add my app to the open in option, by adding my doc types to Info.plist file, but is there a way to do something similar when the share button is pressed in the youtube app on ios?

Similar to android question answered here.

android youtube: share a youtube video TO my app?

like image 986
omgpython Avatar asked Jan 19 '26 12:01

omgpython


1 Answers

Done with me I can share videos opened on Youtube App or Safari

Starting from iOS 8 this became possible with App Share Extension

If you are using SLComposeViewController you will get the URL using

self.contentText

and if you created your custom UIViewController

if([itemProvider hasItemConformingToTypeIdentifier:@"public.plain-text"]) {
            NSLog(@"itemprovider = %@", itemProvider);

            [itemProvider loadItemForTypeIdentifier:@"public.plain-text" options:nil completionHandler: ^(id<NSSecureCoding> item, NSError *error) {

                NSString *url;
                if([(NSObject*)item isKindOfClass:[NSString class]]) {
                    url = (NSString*)item;
                }
            }];
}
else if([itemProvider hasItemConformingToTypeIdentifier:@"public.url"]){
      [itemProvider loadItemForTypeIdentifier:@"public.url" options:nil completionHandler: ^(NSUrl *url, NSError *error) {

                NSString *url = [url absoluteString];


            }];
}

You can achieve that by making a Share Extension app that accepts links in general and If you want youtube links only you can filter the coming link with a regex.

enter image description here enter image description here

When using Youtube iOS app and sharing any video by pressing more opens iOS native action sheet I made a share extension to my app and it showed up in the sharing options.

When my app is selected i receive a link to the video.

I used this regex "https?:\\/\\/(?:[0-9A-Z-]+\\.)?(?:youtu\\.be\\/|youtube\\.com\\S*[^\\w\\-\\s])([\\w\\-]{11})(?=[^\\w\\-]|$)(?![?=&+%\\w]*(?:['\"][^<>]*>|<\\/a>))[?=&+%\\w]*" to detect that the link is a youtube link then I used this regex "((?<=(v|V)/)|(?<=be/)|(?<=(\\?|\\&)v=)|(?<=embed/))([\\w-]++)" to detect the videoId from the link

References: ios8-share-extension-swift

sharing-code-between-original-ios-app-and-app-extension

like image 58
Mohamed Elkassas Avatar answered Jan 22 '26 00:01

Mohamed Elkassas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!