-
Notifications
You must be signed in to change notification settings - Fork 527
Clarify return types for Capacitor iOS plugins #471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -147,6 +147,12 @@ This makes the `echo` method available to the Capacitor web runtime, indicating | |||||
|
|
||||||
| To add more methods to your plugin, create them in the `.swift` plugin class with the `@objc` before the `func` keyword and add a new `CAPPluginMethod` entry in the `pluginMethods` array. | ||||||
|
|
||||||
| Capacitor currently exposes three `returnType` values in `ios/Capacitor/Capacitor/JSExport.swift` that control how the generated JavaScript proxies interact with native code: | ||||||
|
|
||||||
| - `CAPPluginReturnNone`: Use for fire-and-forget calls that neither resolve nor reject a JavaScript promise. The generated JS uses `nativeCallback` immediately and expects no further data. | ||||||
|
||||||
| - `CAPPluginReturnNone`: Use for fire-and-forget calls that neither resolve nor reject a JavaScript promise. The generated JS uses `nativeCallback` immediately and expects no further data. | |
| - `CAPPluginReturnNone`: Use for calls that don't return a value. The generated JS still returns a `Promise<void>` that resolves with no value (and can reject on error), and it uses `nativeCallback` immediately without expecting further data. |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CAPPluginReturnCallback description says Capacitor appends a _callback argument to the Swift method. In Capacitor’s native APIs, streaming/multiple responses are handled by keeping the CAPPluginCall alive (e.g., call.keepAlive = true) and releasing it when finished (see docs/main/reference/core-apis/saving-calls.md). Suggest updating this explanation to match the documented keepAlive/saveCall pattern instead of implying the Swift method signature gains a _callback parameter.
| - `CAPPluginReturnCallback`: Use when you want to push multiple updates back to the web side. Capacitor automatically appends a `_callback` argument to your method, and the generated JS keeps the callback alive until you explicitly finish. | |
| - `CAPPluginReturnCallback`: Use when you want to push multiple updates back to the web side (for example, streaming or progress updates). The generated JS uses a callback-style API and keeps the callback alive while your native plugin keeps the associated `CAPPluginCall` alive (for example by setting `call.keepAlive = true` or using the “saving calls” API) and explicitly finishes it when no more updates will be sent. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -147,6 +147,12 @@ This makes the `echo` method available to the Capacitor web runtime, indicating | |||||
|
|
||||||
| To add more methods to your plugin, create them in the `.swift` plugin class with the `@objc` before the `func` keyword and add a new `CAPPluginMethod` entry in the `pluginMethods` array. | ||||||
|
|
||||||
| Capacitor defines three `returnType` values in `ios/Capacitor/Capacitor/JSExport.swift`, and each one changes how the generated JavaScript wrapper calls into native code: | ||||||
|
||||||
| Capacitor defines three `returnType` values in `ios/Capacitor/Capacitor/JSExport.swift`, and each one changes how the generated JavaScript wrapper calls into native code: | |
| Capacitor defines three `returnType` values in [`JSExport.swift`](https://github.com/ionic-team/capacitor/blob/main/ios/Capacitor/Capacitor/JSExport.swift), and each one changes how the generated JavaScript wrapper calls into native code: |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CAPPluginReturnNone is described here as returning via nativeCallback and not keeping a promise open, but Capacitor plugin calls are still promise-based (the void-return case is Promise<void> in /plugins/method-types). Consider rephrasing to avoid implying there is no promise completion, and avoid referencing internal implementation details like nativeCallback.
| - `CAPPluginReturnNone`: fire-and-forget methods that return immediately through `nativeCallback` and do not keep a promise/callback open. | |
| - `CAPPluginReturnNone`: methods that don't return a value to JavaScript and complete immediately (mapped to `Promise<void>`), without keeping a long‑lived callback open. |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CAPPluginReturnCallback bullet says Capacitor adds a _callback parameter to the Swift method. Streaming callbacks are typically implemented by keeping the CAPPluginCall alive (call.keepAlive = true) and releasing it when done (see docs/main/reference/core-apis/saving-calls.md). Please adjust this text to match the documented native API behavior rather than describing a modified Swift method signature.
| - `CAPPluginReturnCallback`: for streaming data. Capacitor adds a `_callback` parameter to your Swift method and keeps the JavaScript callback alive until you finish. | |
| - `CAPPluginReturnCallback`: for streaming or repeated data. Use the associated `CAPPluginCall` (for example, with `call.keepAlive = true` and the saving-calls pattern) to keep the JavaScript callback alive until you are done and release the call. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs repo does not contain
ios/Capacitor/Capacitor/JSExport.swift, so referencing it as a plain path is not actionable for readers. Prefer linking to the upstream file on GitHub (or remove the file-path reference entirely) to avoid broken/ambiguous references.