Skip to content

Titanium.WatchSession

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.

Extends: Titanium.Module · Since: 5.0.0 · Platforms: iphone

Properties #

ACTIVATION_STATE_ACTIVATED#

Type: Number

The watch is currently activated.

ACTIVATION_STATE_INACTIVE#

Type: Number

The watch is currently inactive.

ACTIVATION_STATE_NOT_ACTIVATED#

Type: Number

The watch is currently not activated.

activationState#

Type: Number

Returns the current activation state of the watch.

apiName#

extended

Type: String

The name of the API that this proxy corresponds to.

The value of this property is the fully qualified name of the API. For example, Button
returns Ti.UI.Button.

bubbleParent#

extended

Type: Boolean

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

Some proxies (most commonly views) have a relationship to other proxies, often
established by the add() method. For example, for a button added to a window, a
click event on the button would bubble up to the window. Other common parents are
table sections to their rows, table views to their sections, and scrollable views
to their views. Set this property to false to disable the bubbling to the proxy's parent.

hasContentPending#

Type: Boolean

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

isActivated#

Type: Boolean

Returns true if the watch is currently activated.

isComplicationEnabled#

Type: Boolean

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

isPaired#

Type: Boolean

Returns true if the device is paired with a watch.

isReachable#

Type: Boolean

Returns true if the watch is currently reachable.

isSupported#

Type: Boolean

Returns true if the device supports watch connectivity.

isWatchAppInstalled#

Type: Boolean

Returns true if the accompanying watch app is installed.

lifecycleContainer#

extended

Type: Titanium.UI.Window, Titanium.UI.TabGroup

The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.

If this property is set to a Window or TabGroup, then the corresponding Activity lifecycle event callbacks
will also be called on the proxy. Proxies that require the activity lifecycle will need this property set
to the appropriate containing Window or TabGroup.

recentApplicationContext#

Type: Dictionary

The most recent application context sent to the watch app.

remainingComplicationUserInfoTransfers#

Type: Number

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

Methods #

activateSession #

Activates the watch session

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

addEventListener #

extended

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

Parameters:
NameTypeSummaryOptional
nameStringName of the event.No
callbackCallback<Titanium.Event>Callback function to invoke when the event is fired.No

applyProperties #

extended

Applies the properties to the proxy.

Properties are supplied as a dictionary. Each key-value pair in the object is applied to the proxy such that
myproxy[key] = value.

Parameters:
NameTypeSummaryOptional
propsDictionaryA dictionary of properties to apply.No

cancelAllFileTransfers #

Cancels all incomplete file transfers to the Apple Watch.

Cancels all incomplete file transfers to the Apple Watch.

cancelAllTransfers #

Cancels all incomplete transfers to the Apple Watch.

Cancels all incomplete transfers to the Apple Watch, including user info, complication and file.

cancelAllUserInfoTransfers #

Cancels all incomplete user info and complication transfers to the Apple Watch.

Cancels all incomplete user info and complication transfers to the Apple Watch.

fireEvent #

extended

Fires a synthesized event to any registered listeners.

Parameters:
NameTypeSummaryOptional
nameStringName of the event.No
eventDictionaryA dictionary of keys and values to add to the Titanium.Event object sent to the listeners.Yes

removeEventListener #

extended

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

Multiple listeners can be registered for the same event, so the
callback parameter is used to determine which listener to remove.

When adding a listener, you must save a reference to the callback function
in order to remove the listener later:

var listener = function() { Ti.API.info("Event listener called."); }
window.addEventListener('click', listener);

To remove the listener, pass in a reference to the callback function:

window.removeEventListener('click', listener);
Parameters:
NameTypeSummaryOptional
nameStringName of the event.No
callbackCallback<Titanium.Event>Callback function to remove. Must be the same function passed to addEventListener.No

sendMessage #

Sends a message to the Apple Watch.

Sends a message to the installed watch app on the Apple Watch in the foreground.

Parameters:
NameTypeSummaryOptional
messageDictionaryMessage to send to the Apple Watch. This property is required and the key of the dictionary
needs to be a String.
No
replyCallback<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.
Yes

transferCurrentComplication #

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:
NameTypeSummaryOptional
paramsDictionaryComplication to be transferred to watch app.No

transferFile #

Transfers a file to the Apple Watch.

Transfers a file to the installed watch app on the Apple Watch in the background. Subsequent
transfers are queued.

Parameters:
NameTypeSummaryOptional
paramsDictionaryPass 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.
No

transferUserInfo #

Transfers an user info to the Apple Watch.

Transfers an user info object to the installed watch app on the Apple Watch in the background.
Subsequent transfers are queued.

Parameters:
NameTypeSummaryOptional
paramsDictionaryuserInfo to be transferred to the Apple Watch.No

updateApplicationContext #

Sends an app context update to the Apple Watch.

Sends an app context update to the Apple Watch. If watch app is in background during transfer,
watch app 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:
NameTypeSummaryOptional
paramsDictionaryApp context to be updated in the Apple Watch.No

Events #

activationCompleted #

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:
NameTypeSummary
isPairedBooleanIf the device is paired with the Apple Watch.
isReachableBooleanIf the Apple Watch is currently reachable.
isWatchAppInstalledBooleanIf the watch app is installed in the Apple Watch.
isComplicationEnabledBooleanIf the complication is enabled in the Apple Watch.
isActivatedBooleanIf the Apple Watch is currently activated. Only available on iOS 9.3
and later. See Titanium.WatchSession.isActivated for more infos.
activationStateNumberReturns the current activation state of the watch. Only available on iOS 9.3
and later. See Titanium.WatchSession.activationState for more infos.

deactivate #

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:
NameTypeSummary
isPairedBooleanIf the device is paired with the Apple Watch.
isReachableBooleanIf the Apple Watch is currently reachable.
isWatchAppInstalledBooleanIf the watch app is installed in the Apple Watch.
isComplicationEnabledBooleanIf the complication is enabled in the Apple Watch.
isActivatedBooleanIf the Apple Watch is currently activated. Only available on iOS 9.3
and later. See Titanium.WatchSession.isActivated for more infos.
hasContentPendingBooleanIf the Apple Watch has currently content pending. Only available on iOS 10.0
and later. See Titanium.WatchSession.hasContentPending for more infos.
remainingComplicationUserInfoTransfersBooleanIf the Apple Watch has complication userInfo transfers left. Only available on iOS 10.0
and later. See Titanium.WatchSession.remainingComplicationUserInfoTransfers for more infos.
activationStateNumberReturns the current activation state of the watch. Only available on iOS 9.3
and later. See Titanium.WatchSession.activationState for more infos.

finishfiletransfer #

App completed file transfer to watch app.

Event Properties:
NameTypeSummary
fileURLStringURL of the file transferred.
metaDataDictionarymeta data of the file transferred.
successBooleanIf the transfer was successful.
errorCodeNumberError code if transfer failed.
messageStringError message if any.

finishuserinfotransfer #

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

Event Properties:
NameTypeSummary
userInfoDictionaryThe downloaded data as a Titanium.Blob object.
successBooleanIf the transfer was successful.
errorCodeNumberError code if transfer failed.
messageStringError message if any.

inactive #

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:
NameTypeSummary
isPairedBooleanIf the device is paired with the Apple Watch.
isReachableBooleanIf the Apple Watch is currently reachable.
isWatchAppInstalledBooleanIf the watch app is installed in the Apple Watch.
isComplicationEnabledBooleanIf the complication is enabled in the Apple Watch.
isActivatedBooleanIf the Apple Watch is currently activated. Only available on iOS 9.3
and later. See Titanium.WatchSession.isActivated for more infos.
activationStateNumberReturns the current activation state of the watch. Only available on iOS 9.3
and later. See Titanium.WatchSession.activationState for more infos.

reachabilitychanged #

The watch reachability state has changed.

Event Properties:
NameTypeSummary
isPairedBooleanIf the device is paired with the Apple Watch.
isReachableBooleanIf the Apple Watch is currently reachable.
isWatchAppInstalledBooleanIf the watch app is installed in the Apple Watch.
isComplicationEnabledBooleanIf the complication is enabled in the Apple Watch.
isActivatedBooleanIf the Apple Watch is currently activated. Only available on iOS 9.3
and later. See Titanium.WatchSession.isActivated for more infos.
activationStateNumberReturns the current activation state of the watch. Only available on iOS 9.3
and later. See Titanium.WatchSession.activationState for more infos.

receiveapplicationcontext #

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

Event Properties:
NameTypeSummary
applicationContextDictionaryThe application Context

receivefile #

App received file from Apple Watch in background.

Event Properties:
NameTypeSummary
dataTitanium.BlobThe downloaded data as a Titanium.Blob object.
metaDataDictionaryInformation about the file.
successBooleanIf the transfer was successful.
errorCodeNumberError code if transfer failed.
messageStringError message if any.

receivemessage #

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

Event Properties:
NameTypeSummary
messageDictionaryThe message content

receiveuserinfo #

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:
NameTypeSummary
userInfoDictionaryThe user info content

watchstatechanged #

The watch state has changed.

Event Properties:
NameTypeSummary
isPairedBooleanIf the device is paired with the Apple Watch.
isReachableBooleanIf the Apple Watch is currently reachable.
isWatchAppInstalledBooleanIf the watch app is installed in the Apple Watch.
isComplicationEnabledBooleanIf the complication is enabled in the Apple Watch.
isActivatedBooleanIf the Apple Watch is currently activated. Only available on iOS 9.3
and later. See Titanium.WatchSession.isActivated for more infos.
activationStateNumberReturns the current activation state of the watch. Only available on iOS 9.3
and later. See Titanium.WatchSession.activationState for more infos.

Titanium SDK Documentation