我可以直接从MacOS应用程序中调用Airdrop(无需浏览共享菜单UI)吗?

发布于 2025-02-05 03:06:41 字数 77 浏览 2 评论 0原文

我有一个MacOS应用程序,我只想通过Airdrop来支持共享。有没有办法使用户无需浏览共享菜单UI即可直接进入AirDrop对话框?谢谢。

I have a macOS app where I want to support sharing via airdrop only. Is there a way to enable users to directly go to the airdrop dialog without going through the share menu UI? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

剪不断理还乱 2025-02-12 03:06:42

link> link>帮助找到相关资源。
这是通过Airdrop直接共享的确切代码。

    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];

The link suggested in the comment helped in finding the relevant resource.
Here is the exact code to share directly via airdrop.

    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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文