objective-c - 如何在 macOS 上找到/注册 url 方案和文件类型处理程序?
问题描述
我正在用 Objective-C 为第三方 macOS 应用程序创建一个插件。我想注册和处理 url 方案(如myscheme://somedatahere
)和文件类型 - 例如,当用户双击文件时,我们的插件应该会收到通知。
由于我的产品只是第三方应用程序的插件,因此代码无法访问应用程序的 NSApplication 实例,也无法访问其事件。因此,我需要创建一个帮助应用程序并将其捆绑在插件包/包中以进行注册和处理。如果这些假设不正确,请告诉我。
插件包安装在Library/Application Support
(用户通常将插件下载到 Downloads 文件夹中,双击它,然后主机应用程序的处理程序将插件复制到 Application Support 文件夹中)。应用程序处理 url 和文件类型将放置在插件包中。该位置由主机应用程序选择。
我有几个不确定性我无法找到答案:
- macOS 如何找到能够处理特定 url 方案和文件类型的应用程序?
- macOS 会自动找到它还是我应该调用一些东西?
- 如果自动找到,即使应用程序位于
Applications
目录外的插件包内,它是否也能正常工作?
解决方案
您可以在Launch Services文档中找到您正在寻找的答案。
如果您检查“应用程序注册”部分,您将看到:
一个内置的后台工具,在系统启动或新用户登录时运行,自动搜索系统、网络、本地和用户域中的应用程序文件夹,并注册在那里找到的任何新应用程序。
Finder 会在发现所有应用程序时自动注册它们,例如当它们被拖到用户的磁盘上或当用户导航到包含它们的文件夹时。
因此,如果您的帮助应用程序通过用户手动拖放安装到 /Library/Application Support 中,看起来启动服务会看到它并注册 URL 方案。
否则,文档将继续涵盖手动案例:
In spite of these automatic registration utilities, it may sometimes be necessary to register an application explicitly with Launch Services. For example, although developers are encouraged to package their applications so that they can be installed by simply dragging them onto the user’s disk, some applications may require more elaborate custom installer software. In such cases, the installer should call one of the Launch Services registration functions LSRegisterFSRef or LSRegisterURL to register the application explicitly.
推荐阅读
- python - 创建 Plotly Choropleth 时出现 ValueError
- php - 如何使php命令永久进程?
- python - 我的python代码中检测到眨眼次数过多的问题。(使用 Eye-Aspect-Ratio 方法)
- vert.x - Vert.x SockJS Socket `.webUser()` 始终为空
- azure - 使用来自不同目录/组织的 WebHook 订阅事件网格域主题
- wordpress - Elementor 自定义媒体控件
- flutter - 我想知道为什么当child为null时Flutter Container中有一个LimitedBox,maxWidth == 0.0有什么意义?
- python - 初学者程序员试图在 python 中重复三遍
- google-cloud-platform - 当 MIG(托管实例组)和负载均衡器位于同一配置文件中时,Google 部署管理器会失败
- android - 无法让agora 工作。本地端给我黑屏,而远程端永远连接不上