打开“邮件应用程序扩展”偏好面板带有MacOS中的Swift

发布于 2025-02-08 17:27:54 字数 1203 浏览 1 评论 0原文

Apple在WWDC21上宣布了邮件应用程序扩展名。该实现与Safari应用程序扩展非​​常相似。使用方法showpreferences forextension(withIdentifier:postemionhandler:) sfsafariapplication 类,可以启动Safari并打开特定Safari应用程序扩展程序的首选项面板。

示例代码:

import SafariServices

SFSafariApplication.showPreferencesForExtension(withIdentifier: "example") { error in
    // error handling...
}

此外,可以检查扩展名的状态。如果启用了扩展名,则可以在容器应用中显示用户很有用。您可以使用getStateOfSafariextension(withIdentifier:pleastionHandler:) sfsafariextensionManager class的方法实现此目标。

示例代码:

import SafariServices

SFSafariExtensionManager.getStateOfSafariExtension(withIdentifier: "example") { state, error in
    // check state and error handling...
}

不幸的是,我还没有找到任何用于邮件应用程序扩展程序的方法。当然,我知道我可以使用nsworkspace>:

if let url = NSWorkspace.shared.urlForApplication(withBundleIdentifier: "com.apple.mail") {
    NSWorkspace.shared.open(url)
}

...但是,这只是一个解决方法,而不是解决方案。我想打开“邮件应用程序扩展”偏好面板并阅读扩展名状态。我为此错过了API吗?

Mail App Extensions were announced by Apple at WWDC21. The implementation is very similar to Safari App Extensions. With the method showPreferencesForExtension(withIdentifier:completionHandler:) of the SFSafariApplication class it is possible to launch Safari and open the preferences panel for a specific Safari app extension.

Example Code:

import SafariServices

SFSafariApplication.showPreferencesForExtension(withIdentifier: "example") { error in
    // error handling...
}

In addition, the state of the extension can be checked. This is useful to show the user in the container app if the extension is enabled. You can implement this using the getStateOfSafariExtension(withIdentifier:completionHandler:) method of the SFSafariExtensionManager class.

Example Code:

import SafariServices

SFSafariExtensionManager.getStateOfSafariExtension(withIdentifier: "example") { state, error in
    // check state and error handling...
}

Unfortunately, I haven't found any ways to implement this for Mail App Extensions yet. Of course, I know that I can open the Mail App quite easily with NSWorkspace:

if let url = NSWorkspace.shared.urlForApplication(withBundleIdentifier: "com.apple.mail") {
    NSWorkspace.shared.open(url)
}

...but this is just a workaround and not a solution. I want to open the "Mail App Extension" preferences panel and read the status of the extension. Am I missing an API for this?

enter image description here

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文