Getting Started
Copy a setup prompt with the install steps and the full markdown guide for this plugin.
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-watch`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/watch/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
Installation
Section titled “Installation”You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:
bunx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsThen use the following prompt:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-watch` plugin in my project.If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:
-
Install the package
Terminal window bun add @capgo/capacitor-watch -
Sync with native projects
Terminal window bunx cap sync -
Configure the plugin
Basic Usage Example:
import { CapgoWatch } from '@capgo/capacitor-watch';// Check watch connectivity statusconst info = await CapgoWatch.getInfo();console.log('Watch paired:', info.isPaired);console.log('Watch reachable:', info.isReachable);// Listen for messages from watchawait CapgoWatch.addListener('messageReceived', (event) => {console.log('Message from watch:', event.message);});Send a Message to Watch:
// Check if watch is reachable firstconst info = await CapgoWatch.getInfo();if (info.isReachable) {await CapgoWatch.sendMessage({data: { action: 'refresh', timestamp: Date.now() }});}Required iOS Setup:
- Add the WatchConnectivity capability to your iOS app in Xcode
- Create a watchOS app target in your Xcode project
- Implement WatchConnectivity in your watchOS app (see Watch App Implementation below)
The plugin automatically activates the WCSession when the plugin loads.
Required Wear OS setup:
- Add a Wear OS module to your Android project (same
applicationIdand signing as the phone app). - Declare the
capgo_watchcapability in the wear module (see Creating a Wear OS app). - Prefer the official Kotlin SDK in
watch-sdk/wearos, or implement Data Layer listeners on the watch using the plugin paths (/capgo/message,/capgo/context, and others).
The phone plugin registers Wearable API listeners when it loads. Use
getInfo()to check connected nodes and whether the watch app is detected.Full steps: Creating a Wear OS app.
-
Handle messages that require a reply
// Listen for messages that need a responseawait CapgoWatch.addListener('messageReceivedWithReply', async (event) => {console.log('Request from watch:', event.message);// Process the requestconst result = await processWatchRequest(event.message);// Send reply back to watch (include requestId for Wear OS correlation)await CapgoWatch.replyToMessage({callbackId: event.callbackId,data: {requestId: event.message.requestId,result,},});}); -
Sync application state
// Update application context (latest value only)await CapgoWatch.updateApplicationContext({context: {theme: 'dark',userId: '123',lastSync: Date.now()}});// Listen for context updates from watchawait CapgoWatch.addListener('applicationContextReceived', (event) => {console.log('Context from watch:', event.context);}); -
Transfer user info reliably
// Queue data for reliable delivery (even when watch is offline)await CapgoWatch.transferUserInfo({userInfo: {recordId: '456',action: 'created',data: { name: 'Item 1' }}});// Listen for user info transfersawait CapgoWatch.addListener('userInfoReceived', (event) => {console.log('User info from watch:', event.userInfo);}); -
Monitor connectivity
// Track reachability changesawait CapgoWatch.addListener('reachabilityChanged', (event) => {console.log('Watch reachable:', event.isReachable);if (event.isReachable) {// Watch is now available for interactive messaging}});// Track session activation stateawait CapgoWatch.addListener('activationStateChanged', (event) => {// 0 = notActivated, 1 = inactive, 2 = activatedconsole.log('Session state:', event.state);});
Quick start
Section titled “Quick start”import { CapgoWatch } from '@capgo/capacitor-watch';
await CapgoWatch.sendMessage({ data: { action: 'refresh', timestamp: Date.now() }});Phone to watch replies and received state
Section titled “Phone to watch replies and received state”These APIs ship in capacitor-watch#36. The plugin README promo covers the same features.
Phone to watch replies
Section titled “Phone to watch replies”sendMessage is one-way by default. Pass expectsReply: true to wait for the watch to reply. The promise resolves with { reply }. reply is the watch payload, or null when the watch returned an empty reply.
On iOS this uses the WatchConnectivity replyHandler. On Android the phone sends on /capgo/message/withreply. Prefer the official Kotlin SDK in watch-sdk/wearos, which reads that envelope and replies on /capgo/reply/{callbackId}. The manual module in Creating a Wear OS app does not handle /capgo/message/withreply unless you add that handler. The watch can include watchRequestId in the payload so concurrent replies stay correlated.
import { CapgoWatch } from '@capgo/capacitor-watch';
const info = await CapgoWatch.getInfo();if (!info.isReachable) { throw new Error('Watch is not reachable for interactive messaging');}
const { reply } = await CapgoWatch.sendMessage({ data: { action: 'getStatus', watchRequestId: 'status-1', }, expectsReply: true,});
console.log('Watch reply:', reply);Leave expectsReply omitted or false when you do not need a reply. The method then resolves with no value, as before.
getReceivedState()
Section titled “getReceivedState()”applicationContextReceived fires when a new context arrives. If your listener was not registered yet, call getReceivedState() to read the last context the plugin already stored.
import { CapgoWatch } from '@capgo/capacitor-watch';
const { context } = await CapgoWatch.getReceivedState();if (context) { console.log('Last context from the watch:', context);}On iOS this is WCSession.receivedApplicationContext. On Android it is the last persisted /capgo/context DataItem. On web the method resolves { context: null }.
Background replay on Android
Section titled “Background replay on Android”When a Wear OS event arrives and no JavaScript listener is registered yet, the phone plugin persists the event and replays it once a listener is added. That covers messages, application context, user info, and reachability. Register listeners early in app startup so replayed events are handled.
Example: updateApplicationContext
Section titled “Example: updateApplicationContext”import { CapgoWatch } from '@capgo/capacitor-watch';
await CapgoWatch.updateApplicationContext({ context: { theme: 'dark', lastSync: Date.now() }});Example: transferUserInfo
Section titled “Example: transferUserInfo”import { CapgoWatch } from '@capgo/capacitor-watch';
await CapgoWatch.transferUserInfo({ userInfo: { recordId: '123', action: 'created' }});Common pitfalls
Section titled “Common pitfalls”- Listeners: remove handles when screens unmount.
- Native sync: run
bunx cap syncafter plugin upgrades. - Source of truth: trust
src/definitions.tsin the GitHub repo.
Watch App Implementation
Section titled “Watch App Implementation”Your watchOS app needs to implement WatchConnectivity. Here’s a SwiftUI example:
import SwiftUIimport WatchConnectivity
@mainstruct MyWatchApp: App { init() { WatchViewModel.shared.activate() }
var body: some Scene { WindowGroup { ContentView() } }}
class WatchViewModel: NSObject, ObservableObject, WCSessionDelegate { static let shared = WatchViewModel()
@Published var lastMessage: [String: Any] = [:]
func activate() { guard WCSession.isSupported() else { return } WCSession.default.delegate = self WCSession.default.activate() }
// Send message to iPhone func sendToPhone(_ data: [String: Any]) { guard WCSession.default.isReachable else { print("iPhone not reachable") return } WCSession.default.sendMessage(data, replyHandler: nil) }
// Send message with reply func sendToPhoneWithReply(_ data: [String: Any], completion: @escaping ([String: Any]) -> Void) { guard WCSession.default.isReachable else { return } WCSession.default.sendMessage(data, replyHandler: completion) }
// Receive one-way messages from iPhone func session(_ session: WCSession, didReceiveMessage message: [String: Any]) { DispatchQueue.main.async { self.lastMessage = message } }
// Receive interactive messages from iPhone (sendMessage with expectsReply: true) func session( _ session: WCSession, didReceiveMessage message: [String: Any], replyHandler: @escaping ([String: Any]) -> Void ) { DispatchQueue.main.async { self.lastMessage = message } replyHandler(["status": "ok"]) }
// Receive application context func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String: Any]) { DispatchQueue.main.async { self.lastMessage = applicationContext } }
// Required delegate methods func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) { print("Watch session activated: \(activationState.rawValue)") }}API Reference
Section titled “API Reference”Methods
Section titled “Methods”sendMessage(options: SendMessageOptions)
Section titled “sendMessage(options: SendMessageOptions)”Send an interactive message to the watch. Requires watch to be reachable.
Parameters:
data: Object - The data to send to the watchexpectsReply: boolean (optional, defaultfalse) - Whentrue, wait for a watch reply and resolve with{ reply }
updateApplicationContext(options: UpdateContextOptions)
Section titled “updateApplicationContext(options: UpdateContextOptions)”Update application context. Only latest value is kept.
Parameters:
context: Object - The context data to sync
transferUserInfo(options: TransferUserInfoOptions)
Section titled “transferUserInfo(options: TransferUserInfoOptions)”Queue user info for reliable delivery.
Parameters:
userInfo: Object - The user info to transfer
replyToMessage(options: ReplyMessageOptions)
Section titled “replyToMessage(options: ReplyMessageOptions)”Reply to a message that requested a response.
Parameters:
callbackId: string - The callback ID from messageReceivedWithReply eventdata: Object - The reply data
getReceivedState()
Section titled “getReceivedState()”Return the last application context received from the watch.
Returns: ReceivedState object with:
context: Object or null - The last context, or null if none is stored
On web this resolves { context: null }.
getInfo()
Section titled “getInfo()”Get watch connectivity status.
Returns: WatchInfo object with:
isSupported: boolean - Whether watch APIs are available on this platformisPaired: boolean - Apple Watch paired (iOS) or at least one Wear OS node connected (Android)isWatchAppInstalled: boolean - Companion watch app installed (iOS) orcapgo_watchcapability detected (Android)isReachable: boolean - Whether the watch is reachable for immediate messagingactivationState: number - Session state (iOS WCSession; Android 2 when a node is connected, 0 otherwise)
getPluginVersion()
Section titled “getPluginVersion()”Get the native plugin version.
Events
Section titled “Events”| Event | Description |
|---|---|
messageReceived | Simple message from watch |
messageReceivedWithReply | Message expecting a reply (includes callbackId) |
applicationContextReceived | Context update from watch |
userInfoReceived | User info transfer from watch |
reachabilityChanged | Watch connectivity changed (iOS and Android) |
activationStateChanged | Session activation state changed (iOS only) |
Communication Patterns
Section titled “Communication Patterns”Immediate Messaging (sendMessage)
Section titled “Immediate Messaging (sendMessage)”- Requires watch to be reachable
- Best for interactive, time-sensitive communication
- Fails immediately if watch is not available
- Pass
expectsReply: trueto wait for a watch reply (see Phone to watch replies and received state)
Application Context (updateApplicationContext)
Section titled “Application Context (updateApplicationContext)”- Latest value only - previous values are overwritten
- Best for syncing current app state
- Delivered when watch becomes available
User Info Transfer (transferUserInfo)
Section titled “User Info Transfer (transferUserInfo)”- Queued and delivered in order
- Best for important data that must be delivered
- Works even when watch is temporarily unreachable
Platform Notes
Section titled “Platform Notes”See the platform support table on the plugin overview for a method-by-method matrix.
iOS (Apple Watch)
Section titled “iOS (Apple Watch)”- Requires iOS 15.0 or later
- Uses WatchConnectivity framework
- Session automatically activates on plugin load
- Supports background delivery for context and user info
- Emits
reachabilityChangedandactivationStateChanged
Android (Wear OS)
Section titled “Android (Wear OS)”- Requires Google Play services with Wear OS Data Layer (
play-services-wearable, included with the plugin) - Phone and wear APKs must share the same
applicationIdand signing key - Watch app must advertise capability
capgo_watch - Emits
reachabilityChangedwhen connected nodes change. Does not emitactivationStateChanged; pollgetInfo()for session-like state - Incoming events are persisted and replayed when JavaScript listeners are registered
- Prefer the official Kotlin SDK in
watch-sdk/wearos - Setup guide: Creating a Wear OS app
- Watch messaging is not supported in the browser
getInfo()resolves withisSupported: falseand other fields at safe defaultsgetPluginVersion()resolves with{ version: "web" }sendMessage,updateApplicationContext,transferUserInfo, andreplyToMessagereject with an unavailable error.getReceivedState()resolves{ context: null }.addListenerresolves a handle via CapacitorWebPlugin, but watch events are unsupported in the browser (callbacks never run)
Common Use Cases
Section titled “Common Use Cases”- Data Sync: Keep watch and phone data in sync
- Remote Control: Control phone features from watch
- Notifications: Send custom notifications to watch
- Health Data: Share fitness and health metrics
- Media Control: Control music playback from watch
- Smart Home: Control devices from your wrist
Troubleshooting
Section titled “Troubleshooting”Watch not reachable:
- Ensure watch is within Bluetooth range
- Check that both apps are running
- Verify WCSession is activated on both sides
Messages not received:
- Check that listeners are registered before sending
- Verify the watch app implements WCSessionDelegate
- Use
transferUserInfofor guaranteed delivery
Session not activating:
- Ensure WatchConnectivity capability is added in Xcode
- Check that watch app has the companion bundle ID
- Verify both apps target compatible OS versions
Keep going from Getting Started
Section titled “Keep going from Getting Started”If you are using Getting Started to plan native plugin work, connect it with Using @capgo/capacitor-watch for the native capability in Using @capgo/capacitor-watch, Capgo Plugin Directory for the product workflow in Capgo Plugin Directory, Capacitor Plugins by Capgo for the implementation detail in Capacitor Plugins by Capgo, Adding or Updating Plugins for the implementation detail in Adding or Updating Plugins, and Ionic Enterprise Plugin Alternatives for the product workflow in Ionic Enterprise Plugin Alternatives.