Sharing specific file types (including zip) in Cocoa using NSSharingServiceNameComposeMessage

Here is my code:

NSSharingService *service = [NSSharingService sharingServiceNamed: NSSharingServiceNameComposeMessage]; tempURL = [NSURL fileURLWithPath:[NSHomeDirectory() stringByAppendingPathComponent:@"test.zip"]] [service performWithItems:@[@"test", tempURL]]; 

The message box displays correctly, as well as the text 'test', but the file is not included in the message.

What works:

  • I know the url is fine because it displays correctly when using a service called NSSharingServiceNameComposeEmail instead
  • zip file is valid; This is a test file that I use already in a known place, and I have already verified that it can be expanded correctly; it is also a very small file
  • I know that a message can have an attached file: the above works for PDF files, page documents, etc.
  • I know that my setting for messages is fine, and it can work with zip files: the "share" button in Finder works fine when used with a zip file and selects the "Send message" option

Related issues:

  • unknown file types also do not work.
  • same problem when using Airdrop NSSharingServiceNameSendViaAirDrop

Any ideas what else I could try? Thanks!

+5
source share
1 answer

Apparently, you can share the zip file, but it does not appear in the general sheet.

I tested it, and when I sent the message to myself, I received the attached zip file.

 - (IBAction)shareZipFile:(id)sender { NSOpenPanel *openPanel = [NSOpenPanel openPanel]; openPanel.allowedFileTypes = @[@"zip"]; openPanel.prompt = @"Share"; [openPanel runModal]; NSSharingService *service = [NSSharingService sharingServiceNamed:NSSharingServiceNameComposeMessage]; NSArray *items = @[openPanel.URL.lastPathComponent.stringByDeletingPathExtension, openPanel.URL]; if (![service canPerformWithItems:items]) { NSLog(@"Can't share that kind of stuff, sorry!"); return; } [service performWithItems:items]; } 
+2
source

All Articles