打开“邮件应用程序扩展”偏好面板带有MacOS中的Swift
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论