如何将操作添加到MACOS FileProvider API并在代码中使用它们?

huangapple go评论73阅读模式
英文:

How to add Actions to MACOS FileProvider API and use them in the Code?

问题

我正在开发一个涉及到FileProvider API的macOS项目。我想要向由FileProvider提供的项目添加自定义操作,并在我的代码中使用它们。我该如何实现这个目标?

具体来说,我想知道:

  1. 如何向macOS FileProvider API添加操作?
  2. 如何定义和自定义这些操作?
  3. 如何在我的代码中处理所选操作的执行?
  4. 如何访问并在我的代码中使用这些操作?

我已经在我的Xcode项目中创建了一个File Provider扩展目标,并实现了必要的协议。我只需要指导如何使用FileProvider API添加和利用这些操作。

我会感激任何示例代码或逐步说明,以帮助我理解和实现这个功能。谢谢!

英文:

I'm working on a macOS project that involves the FileProvider API. I would like to add custom actions to the items provided by the FileProvider and use them in my code. How can I achieve this?

Specifically, I want to know:

How can I add actions to the macOS FileProvider API?
How can I define and customize these actions?
How can I handle the execution of the selected actions in my code?
How can I access and use these actions in my code?
I've already created a File Provider extension target in my Xcode project and implemented the necessary protocols. I just need guidance on how to add and utilize actions with the FileProvider API.

I would appreciate any example code or step-by-step instructions to help me understand and implement this functionality. Thank you!

答案1

得分: 0

我在这里找到了答案:https://developer.apple.com/documentation/fileproviderui/adding_actions_to_the_context_menu

并且你可以像这样使用它,使用 performAction() 方法:

func performAction(identifier actionIdentifier: NSFileProviderExtensionActionIdentifier, 
onItemsWithIdentifiers itemIdentifiers: [NSFileProviderItemIdentifier], 
completionHandler: @escaping (Error?) -> Void) -> Progress {
    switch actionIdentifier.rawValue {

    }

}
英文:

I found my answer here: https://developer.apple.com/documentation/fileproviderui/adding_actions_to_the_context_menu

and you can use it like this using performaction()

 func performAction(identifier actionIdentifier: NSFileProviderExtensionActionIdentifier, 
 onItemsWithIdentifiers itemIdentifiers: [NSFileProviderItemIdentifier], 
 completionHandler: @escaping (Error?) -> Void) -> Progress {
        switch actionIdentifier.rawValue {

}

}

huangapple
  • 本文由 发表于 2023年6月13日 01:21:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76458954.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定