diff --git a/docs/contributing.md b/docs/contributing.md new file mode 100644 index 0000000..f95b392 --- /dev/null +++ b/docs/contributing.md @@ -0,0 +1,10 @@ +# Contributing + +Thanks for your interest in contributing! Please read the [root CONTRIBUTING guide](../CONTRIBUTING.md) for full details. + +## Development workflow + +1. Fork and clone the repository. +2. Install dependencies with `yarn`. +3. Run `yarn lint`, `yarn test`, and `yarn typecheck` before submitting. +4. Open a pull request with a clear description of your changes. diff --git a/docs/setup-watchos.md b/docs/setup-watchos.md new file mode 100644 index 0000000..d3ee92a --- /dev/null +++ b/docs/setup-watchos.md @@ -0,0 +1,21 @@ +# watchOS setup + +These steps show how to link a React Native app with an Apple Watch companion using [`react-native-watch-connectivity`](https://github.com/mtford90/react-native-watch-connectivity). + +1. **Install the library** + + ```sh + yarn add react-native-watch-connectivity + ``` + +2. **Create a watch target** + + In Xcode add a watchOS app or extension to your project and enable Watch Connectivity in the capabilities tab. + +3. **Pair the devices** + + Use the iOS Simulator with a paired watch or a physical iPhone and Apple Watch. + +4. **Run the apps** + + Build the iOS app and watch extension. Use the snippet in `examples/ios-message.ts` to send a test message between the devices. diff --git a/docs/setup-wearos.md b/docs/setup-wearos.md new file mode 100644 index 0000000..20781e1 --- /dev/null +++ b/docs/setup-wearos.md @@ -0,0 +1,38 @@ +# WearOS setup + +Follow these steps to connect a React Native app with a WearOS companion. + +1. **Install the library** + + ```sh + yarn add react-native-wear-connectivity + ``` + +2. **Update `AndroidManifest.xml`** + + Add the required permissions and service to `android/app/src/main/AndroidManifest.xml`. + + ```xml + + + + + + + + + + + ``` + +3. **Pair the devices** + + Install the Google Play Wear app on the Android phone and pair it with the WearOS emulator or device. + +4. **Run the apps** + + Start the Metro server, run the mobile app, and launch the WearOS companion. Use the snippet in `examples/android-message.ts` to verify the connection. diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md new file mode 100644 index 0000000..65708ab --- /dev/null +++ b/docs/troubleshooting.md @@ -0,0 +1,15 @@ +# Troubleshooting + +Common issues when connecting mobile and wearable apps. + +## Wearable app not installed on mobile device + +The mobile device must have the Google Play Wear app installed to pair with the WearOS device. + +## WearOS device too far for Bluetooth connection + +Logcat may show `Device is too far for bluetooth connection` when the watch is out of range of the phone. + +## Failed to deliver message to AppKey + +Ensure the WearOS and mobile apps share the same package name, application ID, and signing key. Messages cannot be delivered if these values differ. diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..1d6bda6 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,8 @@ +# Platform connector examples + +This folder contains minimal code snippets for each supported platform. + +- `android-message.ts` demonstrates sending and receiving a message with the WearOS connector. +- `ios-message.ts` demonstrates sending and receiving a message with the watchOS connector using [`react-native-watch-connectivity`](https://github.com/mtford90/react-native-watch-connectivity). + +Each snippet can be pasted into a React Native project after following the setup guides in the [`docs/`](../docs) directory. diff --git a/examples/android-message.ts b/examples/android-message.ts new file mode 100644 index 0000000..63e55f1 --- /dev/null +++ b/examples/android-message.ts @@ -0,0 +1,13 @@ +import { sendMessage, watchEvents } from 'react-native-wear-connectivity'; + +// Send a message to the WearOS device +sendMessage({ text: 'Hello watch!' }, (reply) => { + console.log('Reply from watch:', reply); +}); + +// Listen for messages from the WearOS device +const unsubscribe = watchEvents.on('message', (message) => { + console.log('Received message from watch', message); +}); + +// Call unsubscribe() when no longer needed diff --git a/examples/ios-message.ts b/examples/ios-message.ts new file mode 100644 index 0000000..b196650 --- /dev/null +++ b/examples/ios-message.ts @@ -0,0 +1,14 @@ +import { sendMessage, watchEvents } from 'react-native-watch-connectivity'; + +// Send a message to the Apple Watch +sendMessage({ text: 'Hello watch!' }, (reply) => { + console.log('Reply from watch:', reply); +}); + +// Listen for messages from the Apple Watch +const unsubscribe = watchEvents.on('message', (message, reply) => { + console.log('Received message from watch', message); + reply({ text: 'Thanks watch!' }); +}); + +// Call unsubscribe() when no longer needed diff --git a/tsconfig.json b/tsconfig.json index d3ffddf..3f7d836 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -24,5 +24,6 @@ "strict": true, "target": "esnext", "verbatimModuleSyntax": true - } + }, + "exclude": ["node_modules", "examples"] }