Using @capgo/capacitor-watch
Apple Watch communication plugin for Capacitor. Provides bidirectional messaging between iPhone and Apple Watch using WatchConnectivity.
Install
bun add @capgo/capacitor-watch
bunx cap sync
What This Plugin Exposes
sendMessage- Apple Watchにインタラクティブなメッセージを送信します。Apple Watchが接続可能な状態でなければなりません。このメッセージはタイムセンシティブな通信に使用します。updateApplicationContext- iPhoneとApple Watch間でアプリケーションコンテキストを共有します。最新のコンテキストのみが保持され、以前のコンテキストは上書きされます。アプリケーション状態をApple Watchに表示する必要がある場合に使用します。transferUserInfo- Apple Watchにユーザー情報を転送します。転送はキュー化され、Apple Watchが現在接続可能な状態でなくても順番に配信されます。重要なデータを信頼性の高い方法で送信する場合に使用します。replyToMessage- Apple Watchから返信を求められたメッセージに返信します。メッセージReceivedWithReplyイベントの応答に使用します。
Example Usage
sendMessage
Apple Watchにインタラクティブなメッセージを送信します。Apple Watchが接続可能な状態でなければなりません。このメッセージはタイムセンシティブな通信に使用します。
import { CapgoWatch } from '@capgo/capacitor-watch';
await CapgoWatch.sendMessage({
data: { action: 'refresh', timestamp: Date.now() }
});
updateApplicationContext
Update the application context shared with the watch. Only the latest context is kept - this overwrites any previous context. Use this for syncing app state that the watch needs to display.
import { CapgoWatch } from '@capgo/capacitor-watch';
await CapgoWatch.updateApplicationContext({
context: { theme: 'dark', lastSync: Date.now() }
});
transferUserInfo
Transfer user info to the watch. Transfers are queued and delivered in order, even if the watch is not currently reachable. Use this for important data that must be delivered reliably.
import { CapgoWatch } from '@capgo/capacitor-watch';
await CapgoWatch.transferUserInfo({
userInfo: { recordId: '123', action: 'created' }
});
replyToMessage
Reply to a message from the watch that requested a reply. Use this in response to the messageReceivedWithReply event.
import { CapgoWatch } from '@capgo/capacitor-watch';
CapgoWatch.addListener('messageReceivedWithReply', async (event) => {
const result = await processRequest(event.message);
await CapgoWatch.replyToMessage({
callbackId: event.callbackId,
data: { result }
});
});
Full Reference
- GitHub https://github.com/Cap-go/capacitor-watch/
- https://__CAPGO_KEEP_0__.com/Cap-go/__CAPGO_KEEP_1__-watch/
Keep going from Using @capgo/capacitor-watch
If you are using Using @capgo/capacitor-watch If you are using Using @capgo/capacitor-watch、nativeプラグインの作業を計画するには、を接続します。@capgo/capacitor-watchと 実装詳細については @capgo/capacitor-watch に Getting Started 実装詳細については Getting Started に Capgo プラグイン ディレクトリ 実装詳細については Capgo プラグイン ディレクトリ に Capacitor プラグイン by Capgo 実装詳細については Capacitor プラグイン by Capgo に プラグインの追加または更新 実装詳細についてはプラグインの追加または更新に