Skip to content
Titanium SDK
Version12.7.1

You are reading 12.7.1. See this page in 13.4.1.

Titanium.WatchSession

moduleiPhonesince 5.0.0

Extends Titanium.ModuleTitanium.Proxy

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

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 15

apiName

Stringsince Android 3.2.0, iPhone 3.2.0, iPad 3.2.0, macOS 9.2.0read-only

Inherited from Titanium.Proxy

The name of the API that this proxy corresponds to.

bubbleParent

Booleansince Android 3.0.0, iPhone 3.0.0, iPad 3.0.0, macOS 9.2.0

Inherited from Titanium.Proxy

Indicates if the proxy will bubble an event to its parent.

Default: true

hasContentPending

Booleansince 6.0.0read-only

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

isActivated

Booleansince 5.4.0read-onlyiOS 9.3+

Returns true if the watch is currently activated.

isComplicationEnabled

Booleanread-only

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

isPaired

Booleanread-only

Returns true if the device is paired with a watch.

isReachable

Booleanread-only

Returns true if the watch is currently reachable.

isSupported

Booleanread-only

Returns true if the device supports watch connectivity.

remainingComplicationUserInfoTransfers

Numbersince 6.0.0read-only

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

Default: 0

Methods 13

Activates the watch session

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

Inherited from Titanium.Proxy

Adds the specified callback as an event listener for the named event.

Parameters
ParametersTypeDescription
nameString

Name of the event.

callbackCallback<Titanium.Event>

Callback function to invoke when the event is fired.

4 fields
bubbles Boolean

True if the event will try to bubble up if possible.

cancelBubble Boolean

Set to true to stop the event from bubbling.

source Object

Source object that fired the event.

type String

Name of the event fired.

Cancels all incomplete file transfers to the apple watch.

Cancels all incomplete file transfers to the apple watch.

Cancels all incomplete transfers to the apple watch.

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

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

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

Inherited from Titanium.Proxy

Fires a synthesized event to any registered listeners.

Parameters
ParametersTypeDescription
nameString

Name of the event.

event?Dictionary

A dictionary of keys and values to add to the Titanium.Event object sent to the listeners.

Inherited from Titanium.Proxy

Removes the specified callback as an event listener for the named event.

Parameters
ParametersTypeDescription
nameString

Name of the event.

callbackCallback<Titanium.Event>

Callback function to remove. Must be the same function passed to addEventListener.

4 fields
bubbles Boolean

True if the event will try to bubble up if possible.

cancelBubble Boolean

Set to true to stop the event from bubbling.

source Object

Source object that fired the event.

type String

Name of the event fired.

Sends a message to the apple watch.

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

Parameters
ParametersTypeDescription
messageDictionary

Message to send to apple watch. This property is required and the key of the dictionary needs to be a String.

reply?Callback<MessageReply>

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.

4 fields
code Number

Error code. Returns 0 if success is true.

error String

Error message, if any returned.

message Dictionary

Reply message from watchapp.

success Boolean

Indicates if the operation succeeded.

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
ParametersTypeDescription
paramsDictionary

Complication to be transferred to watch app.

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
ParametersTypeDescription
paramsDictionary

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.

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
ParametersTypeDescription
paramsDictionary

userInfo to be transferred to apple watch.

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 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
ParametersTypeDescription
paramsDictionary

App context to be updated in apple watch.

Events 11

activationCompleted

since 5.4.0iOS 9.3+

Called when the session has completed activation. If session state is Titanium.WatchSession.ACTIVATION_STATE_NOT_ACTIVATED there will be an error with more details.

Event properties
Event propertiesTypeDescription
isPairedBoolean

If the device is paired with the apple watch.

isReachableBoolean

If apple watch is currently reachable.

isWatchAppInstalledBoolean

If the watch app is installed in the apple watch.

isComplicationEnabledBoolean

If the complication is enabled in the apple watch.

isActivatedBoolean

If the apple watch is currently activated. Only available on iOS 9.3 and later. See Titanium.WatchSession.isActivated for more infos.

activationStateNumber

Returns the current activation state of the watch. Only available on iOS 9.3 and later. See Titanium.WatchSession.activationState for more infos.

deactivate

since 5.4.0iOS 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
Event propertiesTypeDescription
isPairedBoolean

If the device is paired with the apple watch.

isReachableBoolean

If apple watch is currently reachable.

isWatchAppInstalledBoolean

If the watch app is installed in the apple watch.

isComplicationEnabledBoolean

If the complication is enabled in the apple watch.

isActivatedBoolean

If the apple watch is currently activated. Only available on iOS 9.3 and later. See Titanium.WatchSession.isActivated for more infos.

hasContentPendingBoolean

If the apple watch has currently content pending. Only available on iOS 10.0 and later. See Titanium.WatchSession.hasContentPending for more infos.

remainingComplicationUserInfoTransfersBoolean

If the apple watch has complication userInfo transfers left. Only available on iOS 10.0 and later. See Titanium.WatchSession.remainingComplicationUserInfoTransfers for more infos.

activationStateNumber

Returns the current activation state of the watch. Only available on iOS 9.3 and later. See Titanium.WatchSession.activationState for more infos.

App completed file transfer to watch app.

Event properties
Event propertiesTypeDescription
fileURLString

URL of the file transferred.

metaDataDictionary

meta data of the file transferred.

successBoolean

If the transfer was successful.

errorCodeNumber

Error code if transfer failed.

messageString

Error message if any.

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

Event properties
Event propertiesTypeDescription
userInfoDictionary

The downloaded data as a Titanium.Blob object.

successBoolean

If the transfer was successful.

errorCodeNumber

Error code if transfer failed.

messageString

Error message if any.

inactive

since 5.4.0iOS 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
Event propertiesTypeDescription
isPairedBoolean

If the device is paired with the apple watch.

isReachableBoolean

If apple watch is currently reachable.

isWatchAppInstalledBoolean

If the watch app is installed in the apple watch.

isComplicationEnabledBoolean

If the complication is enabled in the apple watch.

isActivatedBoolean

If the apple watch is currently activated. Only available on iOS 9.3 and later. See Titanium.WatchSession.isActivated for more infos.

activationStateNumber

Returns the current activation state of the watch. Only available on iOS 9.3 and later. See Titanium.WatchSession.activationState for more infos.

The watch reachability state has changed.

Event properties
Event propertiesTypeDescription
isPairedBoolean

If the device is paired with the apple watch.

isReachableBoolean

If apple watch is currently reachable.

isWatchAppInstalledBoolean

If the watch app is installed in the apple watch.

isComplicationEnabledBoolean

If the complication is enabled in the apple watch.

isActivatedBoolean

If the apple watch is currently activated. Only available on iOS 9.3 and later. See Titanium.WatchSession.isActivated for more infos.

activationStateNumber

Returns the current activation state of the watch. Only available on iOS 9.3 and later. See Titanium.WatchSession.activationState for more infos.

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

Event properties
Event propertiesTypeDescription
applicationContextDictionary

The application Context

App received file from apple watch in background.

Event properties
Event propertiesTypeDescription
dataTitanium.Blob

The downloaded data as a Titanium.Blob object.

metaDataDictionary

Information about the file.

successBoolean

If the transfer was successful.

errorCodeNumber

Error code if transfer failed.

messageString

Error message if any.

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

Event properties
Event propertiesTypeDescription
messageDictionary

The message content

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
Event propertiesTypeDescription
userInfoDictionary

The user info content

The watch state has changed.

Event properties
Event propertiesTypeDescription
isPairedBoolean

If the device is paired with the apple watch.

isReachableBoolean

If apple watch is currently reachable.

isWatchAppInstalledBoolean

If the watch app is installed in the apple watch.

isComplicationEnabledBoolean

If the complication is enabled in the apple watch.

isActivatedBoolean

If the apple watch is currently activated. Only available on iOS 9.3 and later. See Titanium.WatchSession.isActivated for more infos.

activationStateNumber

Returns the current activation state of the watch. Only available on iOS 9.3 and later. See Titanium.WatchSession.activationState for more infos.