When it comes to developing mobile apps that seamlessly integrate with Apple Watch apps, finding the right tools and frameworks can be a daunting task. That's why we're excited to introduce Expo module wrapping Apple's WatchConnectivity framework for React Native/Expo apps and Apple Watch apps.

To get started, you'll need to install the @plevo/expo-watch-connectivity module using npx expo install @plevo/expo-watch-connectivity. Then, import the WatchConnectivity module in your app and activate the session with await WatchConnectivity.activate();.

Once the session is activated, you can use various methods to communicate with your Apple Watch app. For instance, you can check if the watch is reachable for real-time messaging with if (WatchConnectivity.sessionState.isReachable). You can then send a message using const reply = await WatchConnectivity.sendMessage({ action: 'ping' });.

To listen for incoming messages and respond accordingly, use the addMessageListener method. This will allow you to handle incoming messages and replies in real-time.

Background Syncing and File Transfer

In addition to real-time messaging, Expo's WatchConnectivity module also provides support for background syncing and file transfer. You can update your app's context with await WatchConnectivity.updateApplicationContext({ theme: 'dark', lastSync: Date.now() });.

You can also transfer user info or files using the transferUserInfo and transferFile methods, respectively.

Cleanup

When you're done communicating with your Apple Watch app, don't forget to clean up any listeners you've created. Use the .remove() method to unsubscribe from any events.

Properties and Methods

Here's a breakdown of the various properties and methods available in Expo's WatchConnectivity module:

| Property | Type | Description |

| --- | --- | --- |

| isSupported | boolean | Whether WatchConnectivity is supported (always false on Android) |

| sessionState | SessionState | Current session state including pairing, reachability, etc. |

| applicationContext | Record | Most recently sent application context |

| receivedApplicationContext | Record | Most recently received application context |

| outstandingUserInfoTransfers | UserInfoTransferInfo[] | Pending user info transfers |

| outstandingFileTransfers | FileTransferInfo[] | Pending file transfers |

Listeners

The WatchConnectivity module also provides various listeners that allow you to handle different events. These include:

| Listener | Event Type | Description |

| --- | --- | --- |

| addSessionStateListener | SessionStateChangedEvent | Session state changes |

| addReachabilityListener | ReachabilityChangedEvent | Reachability changes |

| addActivationListener | ActivationDidCompleteEvent | Activation completed |

| addMessageListener | MessageReceivedEvent | Message received |

| addApplicationContextListener | ApplicationContextReceivedEvent | Context received |

| addUserInfoListener | UserInfoReceivedEvent | User info received |

| addFileListener | FileReceivedEvent | File received |

Platform Support

The Expo module wrapping Apple's WatchConnectivity framework is fully supported on iOS, but returns isSupported: false on Android and is not supported on the web.

By using this module, you can create seamless mobile app development experiences for your Apple Watch apps. With its robust set of features and methods, you'll be able to communicate with your watch app in real-time, transfer files and user info, and more.

MIT License

The Expo module wrapping Apple's WatchConnectivity framework is licensed under the MIT license.