我有一个macOS应用程序,我想支持通过空投共享。是否有一种方法可以让用户直接进入空投对话框而无需通过共享菜单UI?谢谢。
发布于 2022-06-09 03:33:33
link在评论中建议帮助找到相关的资源。以下是直接通过空投共享的代码。
std::string filepath = "path_to_file";
NSString* fileUrl = [NSString stringWithUTF8String:filepath.c_str()];
NSURL *url = [NSURL fileURLWithPath:fileUrl];
std::string fileName = "file_name";
NSString* fileName = [NSString fileName.c_str()];
NSSharingService *service = [NSSharingService sharingServiceNamed:NSSharingServiceNameSendViaAirDrop];
NSArray *items = @[fileName, url];
if (![service canPerformWithItems:items]) {
NSLog(@"Can't share that kind of stuff, sorry!");
return;
}
[service performWithItems:items];https://stackoverflow.com/questions/72531684
复制相似问题