我可以让 YouTube 出现在我的 OS X 应用的共享 sheet 中吗?

Can I get YouTube to appear in the share sheet of my OS X app?

根据 Apple documentation,YouTube 不包含在可用的共享服务中,事实上,当我在系统偏好设置中查看共享菜单扩展时,我在那里没有看到它。

在我自己的应用程序中使用 NSSharingServicePicker 呈现分享 sheet 如下也不包括 YouTube。

NSSharingServicePicker *sharingServicePicker = [[NSSharingServicePicker alloc] initWithItems:@[movieFileURL]];
[sharingServicePicker showRelativeToRect:myView.bounds ofView:myView preferredEdge:NSMinYEdge];

但是在 QuickTime Player 或 iMovie 中使用共享 sheet 时,YouTube 是一个选项,如下所示。有什么方法可以让 YouTube 作为一个选项出现在我的应用程序中,或者让 Apple 专门将 YouTube 添加到这些应用程序中,而不将其添加到操作系统范围列表中?

似乎 YouTube 共享选项在操作系统级别不可用,QuickTime Player 和 iMovie 自己实现了它。如果您自己实现共享机制(例如使用 Google's Objective C API),您可以创建一个包含 YouTube 的共享菜单,如下所示(假设您有一个名为 YouTubeSharingServiceNSSharingService 子类):

- (void)addSharingMenuItemsToMenu:(NSMenu *)menu {
    // Get the sharing services for the file.
    NSMutableArray *services = [[NSSharingService sharingServicesForItems:@[self.fileURL]] mutableCopy];
    [services addObject:[YouTubeSharingService new]];

    // Create menu items for the sharing services.
    for (NSSharingService *service in services) {
        NSMenuItem *menuItem = [[NSMenuItem alloc] init];
        menuItem.title = service.menuItemTitle;
        menuItem.image = service.image;
        menuItem.representedObject = service;
        menuItem.target = self;
        menuItem.action = @selector(executeSharingService:);
        [menu addItem:menuItem];
    }
}

- (void)executeSharingService:(id)sender {
    if ([sender isKindOfClass:[NSMenuItem class]]) {
        NSMenuItem *menuItem = sender;
        if ([menuItem.representedObject isKindOfClass:[NSSharingService class]]) {
            NSSharingService *sharingService = menuItem.representedObject;
            [sharingService performWithItems:@[self.fileURL]];
        }
    }
}