pasine
pasine

Reputation: 11543

Create iOS Action Extension with no UI

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?

Upvotes: 4

Views: 3551

Answers (2)

pasine
pasine

Reputation: 11543

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.

Upvotes: 13

Sachin Vas
Sachin Vas

Reputation: 1767

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

Upvotes: 0

Related Questions