# Titanium.WatchSession

> Used to enable data and file transfers between a watchOS and iOS application.

- Source: https://titaniumsdk.com/docs/sdk/12.7.0/Titanium.WatchSession
- Titanium SDK version: 12.7.0
- Kind: module
- Platforms: iPhone
- Since: Titanium SDK 5.0.0
- Extends: Titanium.Module
- Inheritance: Titanium.Module > Titanium.Proxy

WatchSession enables data and file transfers between a WatchKit application and a Titanium application
using the iOS Watch Connectivity framework introduced in iOS 9 and watchOS 2.

## Properties

### ACTIVATION_STATE_ACTIVATED

- Type: Number
- Platforms: iPhone
- Since: Titanium SDK 5.4.0
- Requires: iOS 9.3+
- Permission: read-only

The watch is currently activated.

### ACTIVATION_STATE_INACTIVE

- Type: Number
- Platforms: iPhone
- Since: Titanium SDK 5.4.0
- Requires: iOS 9.3+
- Permission: read-only

The watch is currently inactive.

### ACTIVATION_STATE_NOT_ACTIVATED

- Type: Number
- Platforms: iPhone
- Since: Titanium SDK 5.4.0
- Requires: iOS 9.3+
- Permission: read-only

The watch is currently not activated.

### activationState

- Type: Number
- Platforms: iPhone
- Since: Titanium SDK 5.4.0
- Requires: iOS 9.3+
- Permission: read-only

Returns the current activation state of the watch.

Accepts: `Titanium.WatchSession.ACTIVATION_STATE_ACTIVATED`, `Titanium.WatchSession.ACTIVATION_STATE_INACTIVE`, `Titanium.WatchSession.ACTIVATION_STATE_NOT_ACTIVATED`

### hasContentPending

- Type: Boolean
- Platforms: iPhone
- Since: Titanium SDK 6.0.0
- Permission: read-only

Returns `true` if there is more content for the session to deliver.

### isActivated

- Type: Boolean
- Platforms: iPhone
- Since: Titanium SDK 5.4.0
- Requires: iOS 9.3+
- Permission: read-only

Returns `true` if the watch is currently activated.

### isComplicationEnabled

- Type: Boolean
- Platforms: iPhone
- Permission: read-only

Returns `true` if complication is enabled on the installed watch app.

### isPaired

- Type: Boolean
- Platforms: iPhone
- Permission: read-only

Returns `true` if the device is paired with a watch.

### isReachable

- Type: Boolean
- Platforms: iPhone
- Permission: read-only

Returns `true` if the watch is currently reachable.

### isSupported

- Type: Boolean
- Platforms: iPhone
- Permission: read-only

Returns `true` if the device supports watch connectivity.

### isWatchAppInstalled

- Type: Boolean
- Platforms: iPhone
- Permission: read-only

Returns `true` if the accompanying watch app is installed.

### recentApplicationContext

- Type: Dictionary
- Platforms: iPhone
- Permission: read-only

The most recent application context sent to the watch app.

### remainingComplicationUserInfoTransfers

- Type: Number
- Platforms: iPhone
- Since: Titanium SDK 6.0.0
- Permission: read-only
- Default: `0`

The number of calls remaining to `transferCurrentComplication` before the system starts 
transferring the complicationUserInfo as regular userInfos.

## Methods

### activateSession

- Platforms: iPhone

Activates the watch session

Activates the watch session to make the app ready to receive messages from the watch app.

### cancelAllFileTransfers

- Platforms: iPhone

Cancels all incomplete file transfers to the apple watch.

Cancels all incomplete file transfers to the apple watch.

### cancelAllTransfers

- Platforms: iPhone

Cancels all incomplete transfers to the apple watch.

Cancels all incomplete transfers to the apple watch, including user info, complication and file.

### cancelAllUserInfoTransfers

- Platforms: iPhone

Cancels all incomplete user info and complication transfers to the apple watch.

Cancels all incomplete user info and complication transfers to the apple watch.

### sendMessage

- Platforms: iPhone

Sends a message to the apple watch.

Sends a message to the installed watchapp on the apple watch in the foreground.

Parameters:

- `message` (Dictionary): Message to send to apple watch. This property is required and the key of the dictionary needs to be a String.
- `reply` (Callback<MessageReply>, optional): Function to be called upon receiving a reply from the watch app. **Since Release 5.1.0** This function is used to process the direct reply from the watch app after sending one.

### transferCurrentComplication

- Platforms: iPhone

Transfers complication data to the watch application.

Transfers complication data to the installed watch app. This is only for
watch apps with complications enabled.

Parameters:

- `params` (Dictionary): Complication to be transferred to watch app.

### transferFile

- Platforms: iPhone

Transfers a file to the apple watch.

Transfers a file to the installed watchapp on the apple watch in the background. Subsequent
transfers are queued.

Parameters:

- `params` (Dictionary): Pass an object with the following key-value pairs: * `fileURL` (String) (required): Local filesystem path of file to send to the watch app. * `metaData` (Dictionary) (optional): Additional information about the file to send to the watch app.

### transferUserInfo

- Platforms: iPhone

Transfers an user info to the apple watch.

Transfers an user info object to the installed watchapp on the apple watch in the background.
Subsequent transfers are queued.

Parameters:

- `params` (Dictionary): userInfo to be transferred to apple watch.

### updateApplicationContext

- Platforms: iPhone

Sends an app context update to the apple watch.

Sends an app context update to the apple watch. If watchapp is in background during transfer,
watchapp will fire the [Titanium.WatchSession.receiveapplicationcontext](https://titaniumsdk.com/docs/sdk/Titanium.WatchSession.md#receiveapplicationcontext) event immediately when 
it becomes active. Only one app context is stored at any one time. Subsequent updates will simply 
replace the earlier one sent.

Parameters:

- `params` (Dictionary): App context to be updated in apple watch.

## Events

### activationCompleted

- Platforms: iPhone
- Since: Titanium SDK 5.4.0
- Requires: iOS 9.3+

Called when the session has completed activation. If session state is 
[Titanium.WatchSession.ACTIVATION_STATE_NOT_ACTIVATED](https://titaniumsdk.com/docs/sdk/Titanium.WatchSession.md#ACTIVATION_STATE_NOT_ACTIVATED) there will be an error 
with more details.

Event properties:

- `isPaired` (Boolean): If the device is paired with the apple watch.
- `isReachable` (Boolean): If apple watch is currently reachable.
- `isWatchAppInstalled` (Boolean): If the watch app is installed in the apple watch.
- `isComplicationEnabled` (Boolean): If the complication is enabled in the apple watch.
- `isActivated` (Boolean): If the apple watch is currently activated. Only available on iOS 9.3 and later. See [Titanium.WatchSession.isActivated](https://titaniumsdk.com/docs/sdk/Titanium.WatchSession.md#isActivated) for more infos.
- `activationState` (Number): Returns the current activation state of the watch. Only available on iOS 9.3 and later. See [Titanium.WatchSession.activationState](https://titaniumsdk.com/docs/sdk/Titanium.WatchSession.md#activationState) for more infos.

### deactivate

- Platforms: iPhone
- Since: Titanium SDK 5.4.0
- Requires: iOS 9.3+

Called when all events for the previously selected watch has occurred. 
The session can be re-activated for the now selected watch using activateSession.

Event properties:

- `isPaired` (Boolean): If the device is paired with the apple watch.
- `isReachable` (Boolean): If apple watch is currently reachable.
- `isWatchAppInstalled` (Boolean): If the watch app is installed in the apple watch.
- `isComplicationEnabled` (Boolean): If the complication is enabled in the apple watch.
- `isActivated` (Boolean): If the apple watch is currently activated. Only available on iOS 9.3 and later. See [Titanium.WatchSession.isActivated](https://titaniumsdk.com/docs/sdk/Titanium.WatchSession.md#isActivated) for more infos.
- `hasContentPending` (Boolean): If the apple watch has currently content pending. Only available on iOS 10.0 and later. See [Titanium.WatchSession.hasContentPending](https://titaniumsdk.com/docs/sdk/Titanium.WatchSession.md#hasContentPending) for more infos.
- `remainingComplicationUserInfoTransfers` (Boolean): If the apple watch has complication userInfo transfers left. Only available on iOS 10.0 and later. See [Titanium.WatchSession.remainingComplicationUserInfoTransfers](https://titaniumsdk.com/docs/sdk/Titanium.WatchSession.md#remainingComplicationUserInfoTransfers) for more infos.
- `activationState` (Number): Returns the current activation state of the watch. Only available on iOS 9.3 and later. See [Titanium.WatchSession.activationState](https://titaniumsdk.com/docs/sdk/Titanium.WatchSession.md#activationState) for more infos.

### finishfiletransfer

- Platforms: iPhone

App completed file transfer to watch app.

Event properties:

- `fileURL` (String): URL of the file transferred.
- `metaData` (Dictionary): meta data of the file transferred.
- `success` (Boolean): If the transfer was successful.
- `errorCode` (Number): Error code if transfer failed.
- `message` (String): Error message if any.

### finishuserinfotransfer

- Platforms: iPhone

Fired when the application completed user info transfer to the watch app.

Event properties:

- `userInfo` (Dictionary): The downloaded data as a Titanium.Blob object.
- `success` (Boolean): If the transfer was successful.
- `errorCode` (Number): Error code if transfer failed.
- `message` (String): Error message if any.

### inactive

- Platforms: iPhone
- Since: Titanium SDK 5.4.0
- Requires: iOS 9.3+

Called when the session can no longer be used to modify or add any new transfers and, 
all interactive messages will be cancelled, but events for background transfers can still fire. 
This will happen when the selected watch is being changed.

Event properties:

- `isPaired` (Boolean): If the device is paired with the apple watch.
- `isReachable` (Boolean): If apple watch is currently reachable.
- `isWatchAppInstalled` (Boolean): If the watch app is installed in the apple watch.
- `isComplicationEnabled` (Boolean): If the complication is enabled in the apple watch.
- `isActivated` (Boolean): If the apple watch is currently activated. Only available on iOS 9.3 and later. See [Titanium.WatchSession.isActivated](https://titaniumsdk.com/docs/sdk/Titanium.WatchSession.md#isActivated) for more infos.
- `activationState` (Number): Returns the current activation state of the watch. Only available on iOS 9.3 and later. See [Titanium.WatchSession.activationState](https://titaniumsdk.com/docs/sdk/Titanium.WatchSession.md#activationState) for more infos.

### reachabilitychanged

- Platforms: iPhone

The watch reachability state has changed.

Event properties:

- `isPaired` (Boolean): If the device is paired with the apple watch.
- `isReachable` (Boolean): If apple watch is currently reachable.
- `isWatchAppInstalled` (Boolean): If the watch app is installed in the apple watch.
- `isComplicationEnabled` (Boolean): If the complication is enabled in the apple watch.
- `isActivated` (Boolean): If the apple watch is currently activated. Only available on iOS 9.3 and later. See [Titanium.WatchSession.isActivated](https://titaniumsdk.com/docs/sdk/Titanium.WatchSession.md#isActivated) for more infos.
- `activationState` (Number): Returns the current activation state of the watch. Only available on iOS 9.3 and later. See [Titanium.WatchSession.activationState](https://titaniumsdk.com/docs/sdk/Titanium.WatchSession.md#activationState) for more infos.

### receiveapplicationcontext

- Platforms: iPhone

App received app context from apple watch. Will be called on startup if an applicationContext is available.

Event properties:

- `applicationContext` (Dictionary): The application Context

### receivefile

- Platforms: iPhone

App received file from apple watch in background.

Event properties:

- `data` (Titanium.Blob): The downloaded data as a Titanium.Blob object.
- `metaData` (Dictionary): Information about the file.
- `success` (Boolean): If the transfer was successful.
- `errorCode` (Number): Error code if transfer failed.
- `message` (String): Error message if any.

### receivemessage

- Platforms: iPhone

App received message from apple watch in foreground. Will be called on startup if the 
incoming message caused the receiver to launch.

Event properties:

- `message` (Dictionary): The message content

### receiveuserinfo

- Platforms: iPhone

App received user info from apple watch in background. Will be called on startup if the user info finished 
transferring when the receiver was not running.

Event properties:

- `userInfo` (Dictionary): The user info content

### watchstatechanged

- Platforms: iPhone

The watch state has changed.

Event properties:

- `isPaired` (Boolean): If the device is paired with the apple watch.
- `isReachable` (Boolean): If apple watch is currently reachable.
- `isWatchAppInstalled` (Boolean): If the watch app is installed in the apple watch.
- `isComplicationEnabled` (Boolean): If the complication is enabled in the apple watch.
- `isActivated` (Boolean): If the apple watch is currently activated. Only available on iOS 9.3 and later. See [Titanium.WatchSession.isActivated](https://titaniumsdk.com/docs/sdk/Titanium.WatchSession.md#isActivated) for more infos.
- `activationState` (Number): Returns the current activation state of the watch. Only available on iOS 9.3 and later. See [Titanium.WatchSession.activationState](https://titaniumsdk.com/docs/sdk/Titanium.WatchSession.md#activationState) for more infos.

## Inherited members

6 members are inherited. Each is documented on the type that declares it.

- [Titanium.Proxy](https://titaniumsdk.com/docs/sdk/12.7.0/Titanium.Proxy.md): `addEventListener`, `apiName`, `applyProperties`, `bubbleParent`, `fireEvent`, `removeEventListener`

---

- This corpus documents Titanium SDK 13.4.1. Anything here that does not name a version describes 13.4.1.
- Titanium is maintained by TiDev. The Appcelerator toolchain is retired: there is no `appc` CLI, no Appcelerator Studio and no hosted build service. The supported CLI is `titanium` on npm, invoked as `ti`.

