Repository navigation
3.0.0
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
-
useApplicationContextreturns 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, callgetApplicationContext()instead. -
Errors are
WatchErrorobjects with a stringcode. Promise rejections, thesendMessageerror callback, error events and a failed file transfer'serrorall give aWatchError. Itscodeis aWatchErrorCodesuch as'not-reachable'. It used to be a bare native code such as'7007'.
How to upgrade: compareerror.codewith aWatchErrorCode, or useisWatchError(error, 'not-reachable'). The originalNSErrorvalues are onerror.nativeCodeanderror.domain. -
ERROR_CODE_SESSION_UNREACHABLEis now'not-reachable'and is deprecated. In 2.x it never matched the code an error carried.
How to upgrade: compareerror.codewith'not-reachable'. -
Error events have new payloads:
activation-errorgives{ error },application-context-errorgives{ context, error },user-info-errorgives{ userInfo, error }andfile-received-errorgives{ fileInfo, error }.
How to upgrade: destructure the payload, for example({ error }) => console.warn(error.code). -
session-became-inactiveandsession-did-deactivatelisteners take no arguments.
How to upgrade: remove the payload parameter. You do not need to reactivate the session; the module does it. -
updateApplicationContextreturns a promise. It rejects with aWatchErrorwhen the system refuses the context, for examplepayload-unsupported-typesfor anullvalue. If you neither await it nor attach acatch, a failure is now an unhandled promise rejection. Theapplication-context-errorevent still fires.
How to upgrade:awaitit insidetry/catch, or add.catch(...). -
getApplicationContextresolvesnullwhen this phone has not sent a context. It used to resolve{}.
How to upgrade: check fornullbefore reading keys. -
The
application-context-received-errorevent is removed. It reported failures of the echo that 3.0.0 removes (see Fixes).
How to upgrade: remove the listener. -
paired,installedandreachabilityevents 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. -
_getMissedUserInfois no longer exported. It was internal.
How to upgrade: listen touser-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()returnsfalse, sends reject withsession-not-supported, and state queries resolvefalse,0,nullor{}. Android used to export only the four hooks.
How to upgrade: remove platform guards around imports, and checkisSupported()before showing watch features.
Fixes
- A context received from the watch is no longer sent back to the watch. The module used to call
updateApplicationContextwith every received context, which also replaced the context this phone sends. - Sends no longer hang on devices without WatchConnectivity, such as iPads.
sendMessage,sendMessageData,startFileTransferandupdateApplicationContextreject withsession-not-supported. - The session reactivates after the user switches to another paired watch.
paired,installedandreachabilityevents 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
NSErrorobject, 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.
getQueuedUserInfoandgetQueuedFilesno 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 isfalsewhere 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()andgetRemainingComplicationUserInfoTransfers(), to use with the existingtransferCurrentComplicationUserInfo(info). Both readfalseand0until the session finishes activating shortly after launch.WatchError,isWatchError(error, code?),WATCH_ERROR_CODESand theWatchErrorCodetype.
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