Capacitor plugins can be installed using two methods. This repository natively supports both approaches.
The recommended approach is to use the standard Capacitor CLI. To add a new plugin via NPM:
- Install the plugin from NPM:
npm install <plugin-name>
- Sync the plugin to the iOS workspace:
npx cap sync ios
The Capacitor CLI will automatically generate the SPM (Swift Package Manager) configuration and integrate the new native dependencies into the Xcode workspace.
If you prefer to vendor native dependencies or do not use the Capacitor CLI, you can wire plugins manually using Git Submodules and Xcode's SPM integration. The repo uses this manual approach for the @capacitor/preferences plugin as a working example.
- Vendor the plugin's repository as a Git Submodule:
# Example: official Capacitor plugins git submodule add https://github.com/ionic-team/capacitor-plugins.git Vendor/capacitor-plugins # Example: EGYM NFC Pass Wallet git submodule add https://github.com/egym/lib-capacitor-nfc-pass-wallet.git Vendor/lib-capacitor-nfc-pass-wallet
- In Xcode, select
File -> Add Package Dependencies -> Add Localand choose the folder containing thePackage.swiftfile (e.g.,Vendor/capacitor-plugins/preferencesorVendor/lib-capacitor-nfc-pass-wallet).
Regardless of the installation method, you must register the native plugin in your Portal initialization code. See ContentView.swift for an example:
import PreferencesPlugin
import CapacitorNFCPassWalletPlugin
...
plugins: [.type(PreferencesPlugin.self), .type(CapacitorNFCPassWalletPlugin.self)],