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