这是我的代码:
NSSharingService *service = [NSSharingService sharingServiceNamed: NSSharingServiceNameComposeMessage];
tempURL = [NSURL fileURLWithPath:[NSHomeDirectory() stringByAppendingPathComponent:@"test.zip"]]
[service performWithItems:@[@"test", tempURL]];
Run Code Online (Sandbox Code Playgroud)
正确显示消息窗口以及"测试"文本,但该消息中不包含该文件.
什么有效:
NSSharingServiceNameComposeEmail,而不是类似问题:
NSSharingServiceNameSendViaAirDrop任何想法我还能尝试什么?谢谢!
显然您可以共享 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)