According to Apple documentation, YouTube is not included in the available sharing services, and indeed when I look at the Share Menu extensions in System Preferences I do not see it there.
Presenting the sharing sheet in my own app using NSSharingServicePicker
as follows does not include YouTube either.
NSSharingServicePicker *sharingServicePicker = [[NSSharingServicePicker alloc] initWithItems:@[movieFileURL]];
[sharingServicePicker showRelativeToRect:myView.bounds ofView:myView preferredEdge:NSMinYEdge];
However when using the share sheet in QuickTime Player or iMovie, YouTube is an option, as shown below. Is there any way to get YouTube to appear as an option in my app or have Apple just added YouTube to these apps specifically without adding it to the operating system wide list?
It seems that the YouTube sharing option is not available at the operating system level and that QuickTime Player and iMovie implement it themselves. If you implement the sharing mechanism yourself (e.g. using Google's Objective C API) you can create a sharing menu containing YouTube as follows (this assumes that you have a NSSharingService
subclass called 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]];
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With