Share video from youtube app to my app on ios

佐手、 提交于 2019-12-12 12:28:09

问题


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?


回答1:


Impossible..

First think how to put icon or your app Share option in to YouTube App..? I don't think you can do this in iOS.. because Sharing option Provide by YouTube we can not able to changes in to YouTube API or YouTube App. how to put icon or your app Share option in to YouTube App?




回答2:


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.

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



来源:https://stackoverflow.com/questions/17660718/share-video-from-youtube-app-to-my-app-on-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!