diff --git a/docs/plugins/creating-plugins/ios-guide.md b/docs/plugins/creating-plugins/ios-guide.md index 195fd218e..28686dd34 100644 --- a/docs/plugins/creating-plugins/ios-guide.md +++ b/docs/plugins/creating-plugins/ios-guide.md @@ -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. +- `CAPPluginReturnPromise`: The default. The generated JS returns a `Promise` that you must resolve or reject once per call. +- `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. + ## Permissions If your plugin has functionality on iOS that requires permissions from the end user, then you will need to implement the permissions pattern. diff --git a/versioned_docs/version-v7/plugins/creating-plugins/ios-guide.md b/versioned_docs/version-v7/plugins/creating-plugins/ios-guide.md index 195fd218e..7e820a8c4 100644 --- a/versioned_docs/version-v7/plugins/creating-plugins/ios-guide.md +++ b/versioned_docs/version-v7/plugins/creating-plugins/ios-guide.md @@ -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: + +- `CAPPluginReturnNone`: fire-and-forget methods that return immediately through `nativeCallback` and do not keep a promise/callback open. +- `CAPPluginReturnPromise`: the standard promise-based bridge where you resolve or reject once per invocation. +- `CAPPluginReturnCallback`: for streaming data. Capacitor adds a `_callback` parameter to your Swift method and keeps the JavaScript callback alive until you finish. + ## Permissions If your plugin has functionality on iOS that requires permissions from the end user, then you will need to implement the permissions pattern.