rn-watch-connectv2.0

Application Context

Send the Watch your latest values. Each update replaces the previous one, and only the most recent is delivered.

The Application Context is a dictionary describing the latest values the other side needs, such as a selected theme or the current score. It's delivered in the background, so the Watch doesn't have to be reachable. Only the most recent one is delivered: each update replaces the previous one.

Because an update replaces the whole dictionary, send everything the Watch needs each time, not just what changed. If every value matters, not only the latest, queue User Info instead.

Each side has its own Application Context:

A dictionary's values must be ones WatchConnectivity can carry: strings, numbers, booleans, arrays and nested objects.

updateApplicationContext

updateApplicationContext<T extends Record<string, any>>(applicationContext: T): Promise<void>

Sends a new Application Context to the Watch, replacing the previous one. The Watch app receives it in session(_:didReceiveApplicationContext:).

Type parameters

NameDescription
TThe shape of the Application Context you send.

Parameters

NameTypeDescription
applicationContextTThe full Application Context.

Returns Promise<void>, which resolves once the Session has taken the update. Delivery happens later, in the background.

Throws (the Promise rejects with):

CodeWhen
ERR_PAYLOAD_UNSUPPORTED_TYPESThe dictionary contains a value WatchConnectivity can't carry.
ERR_PAYLOAD_TOO_LARGEThe dictionary is too large to send.
ERR_UNSUPPORTED_PLATFORMCalled on a platform other than iOS.

WatchConnectivity can fail with other codes too, such as ERR_SESSION_NOT_ACTIVATED, ERR_DEVICE_NOT_PAIRED or ERR_WATCH_APP_NOT_INSTALLED. See Error codes for the full list.

Its error message starts with Expo's prefix, "Calling the 'updateApplicationContext' function has failed", so match on code.

Example

import  from "rn-watch-connect";

type  = { : "light" | "dark"; : "metric" | "imperial" };

await .<>({
  : "dark",
  : "metric",
});

applicationContext

readonly applicationContext: Record<string, any>

The last Application Context this iPhone sent with updateApplicationContext. It's {} when there's none, and on platforms other than iOS.

Example

import  from "rn-watch-connect";

// Change one value and send the rest unchanged.
await .({
  ....,
  : "light",
});

receivedApplicationContext

readonly receivedApplicationContext: Record<string, any>

The last Application Context received from the Watch. It's {} when there's none, and on platforms other than iOS. Read it for the starting value, then listen to onApplicationContextChanged for new ones.

onApplicationContextChanged

onApplicationContextChanged: (applicationContext: Record<string, any>) => void

Fires when a new Application Context arrives from the Watch. The listener gets the whole dictionary, which replaces the previous one.

It fires only when one actually arrives, not when you add a listener. For the starting value, read receivedApplicationContext.

Example

import {  } from "expo";
import  from "rn-watch-connect";

export function () {
  const  = (
    ,
    "onApplicationContextChanged",
    .,
  );
  return `Theme on the Watch: ${.theme ?? "default"}`;
}

On this page