iphone - 将视频从 youtube 应用分享到我在 ios 上的应用

标签 iphone ios youtube share

当我在 ios 上的 youtube 应用程序中点击视频上的分享按钮时,是否可以让我的应用程序出现?

我知道如何通过将我的文档类型添加到 Info.plist 文件来将我的应用程序添加到打开方式选项,但是在 ios 上的 youtube 应用程序中按下共享按钮时,有没有办法做类似的事情?

类似于此处回答的 android 问题。

android youtube: share a youtube video TO my app?

最佳答案

我做完了 我可以分享在 Youtube App 或 Safari 上打开的视频

从 iOS 8 开始,这通过应用共享扩展成为可能

如果您使用的是 SLComposeViewController,您将使用

获取 URL
self.contentText

如果您创建了自定义 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];


            }];
}

您可以通过 making a Share Extension app that accepts links 实现一般来说,如果您只想要 YouTube 链接,您可以使用正则表达式过滤即将到来的链接。

enter image description here enter image description here

当使用 Youtube iOS 应用程序并通过按更多键分享任何视频时,打开 iOS 原生操作表 我对我的应用程序进行了共享扩展,它显示在共享选项中。

当我的应用程序被选中时,我会收到一个指向视频的链接。

我使用了这个正则表达式 "https?:\\/\\/(?:[0-9A-Z-]+\\.)?(?:youtu\\.be\\/|youtube\\.com\\S*[^\\w\\-\\s])([\\w\\-]{11})(?=[^\\w\\-]|$)(?![?=&+%\\w]*(?:['\"][^<>]*>|<\\/a>))[?=&+%\\w]*"检测到该链接是一个 youtube 链接然后我使用了这个正则表达式 "((?<=(v|V)/)|(?<=be/)|(?<=(\\?|\\&)v=)|(?<=embed/))([\\w-]++)"从链接中检测videoId

引用资料: ios8-share-extension-swift

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

关于iphone - 将视频从 youtube 应用分享到我在 ios 上的应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17660718/

相关文章:

ios - 如何停止将选择状态转发到嵌入式 tableViewController?

youtube - 如何通过API获取所有列表YouTube channel ?

html - youtube 视频无法正确调整大小

iphone - iTunes 商店会接受基于 Safari 的 iPhone 应用程序吗?

iphone - UIView 范围外的用户交互

iphone - CSS3 支持 : iPhone Safari VS Android default browser?

ios - 从 UIGraphicsImageContext 裁剪区域 CGRect

ios - xCode Objective-C : Tapping UITableViewCells without indexPath. 行

ios - 为什么使用 Alamofire 请求失败?

youtube - 列出 channel 订阅仅返回我的 channel