Skip to content

3.0.0

Choose a tag to compare

@mtford90 mtford90 released this 21 Nov 04:21
· 2 commits to master since this release

3.0.0 makes application context reliable in both directions and gives every error a typed WatchError with a stable code.
It also makes the package safe to import on iPads, the web and Android, and adds getters for complication transfers.

Breaking changes

  • useApplicationContext returns the context the watch sent. It used to return the context this phone last sent.
    How to upgrade: if you used the hook to read back your own context, call getApplicationContext() instead.

  • Errors are WatchError objects with a string code. Promise rejections, the sendMessage error callback, error events and a failed file transfer's error all give a WatchError. Its code is a WatchErrorCode such as 'not-reachable'. It used to be a bare native code such as '7007'.
    How to upgrade: compare error.code with a WatchErrorCode, or use isWatchError(error, 'not-reachable'). The original NSError values are on error.nativeCode and error.domain.

  • ERROR_CODE_SESSION_UNREACHABLE is now 'not-reachable' and is deprecated. In 2.x it never matched the code an error carried.
    How to upgrade: compare error.code with 'not-reachable'.

  • Error events have new payloads: activation-error gives { error }, application-context-error gives { context, error }, user-info-error gives { userInfo, error } and file-received-error gives { fileInfo, error }.
    How to upgrade: destructure the payload, for example ({ error }) => console.warn(error.code).

  • session-became-inactive and session-did-deactivate listeners take no arguments.
    How to upgrade: remove the payload parameter. You do not need to reactivate the session; the module does it.

  • updateApplicationContext returns a promise. It rejects with a WatchError when the system refuses the context, for example payload-unsupported-types for a null value. If you neither await it nor attach a catch, a failure is now an unhandled promise rejection. The application-context-error event still fires.
    How to upgrade: await it inside try/catch, or add .catch(...).

  • getApplicationContext resolves null when this phone has not sent a context. It used to resolve {}.
    How to upgrade: check for null before reading keys.

  • The application-context-received-error event is removed. It reported failures of the echo that 3.0.0 removes (see Fixes).
    How to upgrade: remove the listener.

  • paired, installed and reachability events fire each time the session activates, including at every launch and after a watch switch, even when the value has not changed.
    How to upgrade: make these handlers safe to run with an unchanged value.

  • A buffered event is delivered only when JS listens to that event. Events used to be delivered all together to the first listener of any kind.
    How to upgrade: add a listener for each event you need. Nothing else changes.

  • _getMissedUserInfo is no longer exported. It was internal.
    How to upgrade: listen to user-info; its first call includes user info that arrived before the listener.

  • Android, the web and other platforms get the full API as a no-op. isSupported() returns false, sends reject with session-not-supported, and state queries resolve false, 0, null or {}. Android used to export only the four hooks.
    How to upgrade: remove platform guards around imports, and check isSupported() before showing watch features.

Fixes

  • A context received from the watch is no longer sent back to the watch. The module used to call updateApplicationContext with every received context, which also replaced the context this phone sends.
  • Sends no longer hang on devices without WatchConnectivity, such as iPads. sendMessage, sendMessageData, startFileTransfer and updateApplicationContext reject with session-not-supported.
  • The session reactivates after the user switches to another paired watch. paired, installed and reachability events then report the new watch.
  • Importing the package on the web, in Node or in a web bundler loads the no-op implementation instead of crashing or failing to resolve ./RNWatch.
  • The Android module builds. It implements the spec and reports that WatchConnectivity is not supported.
  • Error events and failed file transfers no longer send an NSError object, which the bridge cannot serialise.
  • The event buffer, received queues and reply handlers are thread-safe. A message that arrived while JS added its first listener could crash the app.
  • getQueuedUserInfo and getQueuedFiles no longer resolve {}. They emptied the queue before JS received it.
  • Reply handlers for messages from the watch are no longer evicted under memory pressure, and each is released after it replies.

New APIs

  • isSupported(): a synchronous check. It is false where WatchConnectivity is unavailable: iPads, Android and the web.
  • getReceivedApplicationContext(): the context the watch last sent, including one that arrived while the app was not running.
  • getIsComplicationEnabled() and getRemainingComplicationUserInfoTransfers(), to use with the existing transferCurrentComplicationUserInfo(info). Both read false and 0 until the session finishes activating shortly after launch.
  • WatchError, isWatchError(error, code?), WATCH_ERROR_CODES and the WatchErrorCode type.

Tests

  • Jest tests cover the JS API, and XCTest tests cover the native module in the example app.

Upgrading

The migration guide has a before and after example for each breaking change: https://watch-connectivity.github.io/react-native-watch-connectivity/docs/migrating-to-3

Full changelog: 2.0.0...3.0.0