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

Dan*_*bbs 5 youtube macos sharing

根据Apple文档,YouTube不包含在可用的共享服务中,实际上当我查看"系统偏好设置"中的"共享菜单"扩展时,我看不到它.

使用NSSharingServicePicker如下方式在我自己的应用程序中显示共享表也不包括YouTube.

NSSharingServicePicker *sharingServicePicker = [[NSSharingServicePicker alloc] initWithItems:@[movieFileURL]];
[sharingServicePicker showRelativeToRect:myView.bounds ofView:myView preferredEdge:NSMinYEdge];
Run Code Online (Sandbox Code Playgroud)

但是,在QuickTime Player或iMovie中使用共享表时,YouTube是一个选项,如下所示.有没有办法让YouTube在我的应用程序中显示为一个选项,或者Apple是否只是将YouTube添加到这些应用程序而不将其添加到操作系统范围列表中?

YouTube在QuickTime播放器中共享 YouTube在iMovie中分享

Dan*_*bbs 4

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

- (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]];
        }
    }
}
Run Code Online (Sandbox Code Playgroud)