3

I am trying to create an Action Extension similar to the system "Copy" action available in iOS.
I found different answers saying it's not possible to have non-fullscreen UI, but according to Apple Official Documentation it is possible to have no UI (like in the Copy action, I presume).

Action (iOS and macOS; UI and non-UI variants)

I have tried creating a transparent view, but the result is always a fullscreen black overlay.
I have already specified NSExtensionActionWantsFullScreenPresentation to NO in my Info.plist, but nothing changes.

Any idea about how to do it?

pasine
  • 11,311
  • 10
  • 49
  • 81

2 Answers2

11

To answer my own question: it is actually possible to create a non-UI Action Extension on iOS by assigning the property NSExtensionPrincipalClass to a class implementing a NSExtensionRequestHandling protocol.

Example:

class ActionRequestHandler: NSObject, NSExtensionRequestHandling {

    var extensionContext: NSExtensionContext?

    func beginRequest(with context: NSExtensionContext) {
        // Do not call super in an Action extension with no user interface
        self.extensionContext = context

        // Do stuff with the context

    }
}

The easiest way to create an extension like this is to add a new target (File > New > Target), select Action Extension and then select No User Interface in the Action Type.

pasine
  • 11,311
  • 10
  • 49
  • 81
  • Hi @pasine. Could you please let me know if it is possible to invoke this extension programmatically from the containing app? – Arjuna Aug 07 '21 at 06:30
  • Sorry, it's something I haven't tried, so I don't have an answer. – pasine Aug 26 '21 at 08:15
0

In iOS, an Action extension:

  • Helps users view the current document in a different way

  • Always appears in an action sheet or full-screen modal view

  • Receives selected content only if explicitly provided by the host app

pasine
  • 11,311
  • 10
  • 49
  • 81
Sachin Vas
  • 1,757
  • 12
  • 16