使用NSSharingServiceNameComposeMessage在Cocoa中共享某些类型的文件(包括zip)

cha*_*les 5 cocoa

这是我的代码:

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

正确显示消息窗口以及"测试"文本,但该消息中不包含该文件.

什么有效:

  • 我知道网址是好的,因为使用命名的服务时,它正确地显示NSSharingServiceNameComposeEmail,而不是
  • zip文件有效; 它是我已经在已知位置使用的测试文件,我已经检查过它可以正确扩展; 它也是一个非常小的文件
  • 我知道一条消息可以附加一个文件:以上适用于PDF,Pages文档等...
  • 我知道我的消息设置很好,它可以使用zip文件:当与zip文件一起使用并选择"发送消息"选项时,Finder中的"共享"按钮工作正常

类似问题:

  • 未知的文件类型也不起作用
  • 使用Airdrop服务时同样的问题 NSSharingServiceNameSendViaAirDrop

任何想法我还能尝试什么?谢谢!

Gui*_*mbo 2

显然您可以共享 zip 文件,但它不会显示在共享表上。

我测试了它,当我向自己发送消息时,我收到了附加的 zip 文件。

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