Skip to content

feat(ios): support async Swift plugin methods (completionHandler:) in PluginManager#14148

Merged
lucasfernog merged 3 commits into
tauri-apps:devfrom
Choochmeque:swift-async-support
Oct 2, 2025
Merged

feat(ios): support async Swift plugin methods (completionHandler:) in PluginManager#14148
lucasfernog merged 3 commits into
tauri-apps:devfrom
Choochmeque:swift-async-support

Conversation

@Choochmeque
Copy link
Copy Markdown
Contributor

This adds support for invoking plugin methods that Swift exposes as async / async throws.
In the Objective-C runtime, such methods are automatically bridged into selectors with a completionHandler: parameter (e.g. commandName:completionHandler:).
• Detects and invokes completionHandler: selectors with a block that rejects if an error is passed.
• Falls back to the existing error: selector for throwing methods.
• No breaking changes — plugins can now use either throws or async/await Swift APIs.

Code example:

    @objc public func getProducts(_ invoke: Invoke) async throws {
        let args = try invoke.parseArgs(GetProductsArgs.self)
        
        do {
            let products = try await Product.products(for: args.productIds)
            var productsArray: [[String: Any]] = []
            
            // Other code

            invoke.resolve(["products": productsArray])
        } catch {
            invoke.reject("Failed to fetch products: \(error.localizedDescription)")
        }
    }	

Without this change, async Swift plugin methods cannot be called and result is "No command getProducts found for plugin"

@Choochmeque Choochmeque requested a review from a team as a code owner September 4, 2025 09:58
@Choochmeque
Copy link
Copy Markdown
Contributor Author

@FabianLars, could you please review this PR?

@FabianLars
Copy link
Copy Markdown
Member

I'm out of office for the next 2-3 so no promises that I can squeeze it in in that timeframe.

@Choochmeque
Copy link
Copy Markdown
Contributor Author

@FabianLars No worries at all.
I have a workaround in place for now:

    @objc public func getProducts(_ invoke: Invoke) throws {
        Task {
            try await self.getProducts(invoke)
        }
    }

@lucasfernog lucasfernog self-assigned this Oct 2, 2025
lucasfernog
lucasfernog previously approved these changes Oct 2, 2025
Copy link
Copy Markdown
Member

@lucasfernog lucasfernog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohh nice catch!

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Oct 2, 2025

Package Changes Through d7a3d0b

There are 9 changes which include @tauri-apps/api with minor, tauri-cli with minor, tauri-utils with minor, tauri-runtime-wry with minor, tauri-runtime with minor, tauri with minor, tauri-bundler with minor, @tauri-apps/cli with minor, tauri-macros with patch

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
@tauri-apps/api 2.8.0 2.9.0
tauri-utils 2.7.0 2.8.0
tauri-bundler 2.6.1 2.7.0
tauri-runtime 2.8.0 2.9.0
tauri-runtime-wry 2.8.1 2.9.0
tauri-codegen 2.4.0 2.4.1
tauri-macros 2.4.0 2.4.1
tauri-plugin 2.4.0 2.4.1
tauri-build 2.4.1 2.4.2
tauri 2.8.5 2.9.0
@tauri-apps/cli 2.8.4 2.9.0
tauri-cli 2.8.4 2.9.0

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

@lucasfernog lucasfernog merged commit 2e089f6 into tauri-apps:dev Oct 2, 2025
19 of 20 checks passed
@Choochmeque Choochmeque deleted the swift-async-support branch December 22, 2025 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants