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 #
apiName#
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#
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.
isComplicationEnabled#
Type: Boolean
Returns true if complication is enabled on the installed watch app.
lifecycleContainer#
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.
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 #
Adds the specified callback as an event listener for the named event.
| Name | Type | Summary | Optional |
|---|---|---|---|
name | String | Name of the event. | No |
callback | Callback<Titanium.Event> | Callback function to invoke when the event is fired. | No |
applyProperties #
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.
| Name | Type | Summary | Optional |
|---|---|---|---|
props | Dictionary | A 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 #
Fires a synthesized event to any registered listeners.
| Name | Type | Summary | Optional |
|---|---|---|---|
name | String | Name of the event. | No |
event | Dictionary | A dictionary of keys and values to add to the Titanium.Event object sent to the listeners. | Yes |
removeEventListener #
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);
| Name | Type | Summary | Optional |
|---|---|---|---|
name | String | Name of the event. | No |
callback | Callback<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.
| Name | Type | Summary | Optional |
|---|---|---|---|
message | Dictionary | Message to send to the Apple Watch. This property is required and the key of the dictionary needs to be a String. | No |
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. | 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.
| Name | Type | Summary | Optional |
|---|---|---|---|
params | Dictionary | Complication 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.
| Name | Type | Summary | Optional |
|---|---|---|---|
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. | 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.
| Name | Type | Summary | Optional |
|---|---|---|---|
params | Dictionary | userInfo 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.
| Name | Type | Summary | Optional |
|---|---|---|---|
params | Dictionary | App 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.
| Name | Type | Summary |
|---|---|---|
isPaired | Boolean | If the device is paired with the Apple Watch. |
isReachable | Boolean | If the 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 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 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.
| Name | Type | Summary |
|---|---|---|
isPaired | Boolean | If the device is paired with the Apple Watch. |
isReachable | Boolean | If the 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 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 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 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 for more infos. |
finishfiletransfer #
App completed file transfer to watch app.
| Name | Type | Summary |
|---|---|---|
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 #
Fired when the application completed user info transfer to the watch app.
| Name | Type | Summary |
|---|---|---|
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 #
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.
| Name | Type | Summary |
|---|---|---|
isPaired | Boolean | If the device is paired with the Apple Watch. |
isReachable | Boolean | If the 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 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 for more infos. |
reachabilitychanged #
The watch reachability state has changed.
| Name | Type | Summary |
|---|---|---|
isPaired | Boolean | If the device is paired with the Apple Watch. |
isReachable | Boolean | If the 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 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 for more infos. |
receiveapplicationcontext #
App received app context from Apple Watch. Will be called on startup if an applicationContext is available.
| Name | Type | Summary |
|---|---|---|
applicationContext | Dictionary | The application Context |
receivefile #
App received file from Apple Watch in background.
| Name | Type | Summary |
|---|---|---|
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 #
App received message from Apple Watch in foreground. Will be called on startup if the
incoming message caused the receiver to launch.
| Name | Type | Summary |
|---|---|---|
message | Dictionary | The 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.
| Name | Type | Summary |
|---|---|---|
userInfo | Dictionary | The user info content |
watchstatechanged #
The watch state has changed.
| Name | Type | Summary |
|---|---|---|
isPaired | Boolean | If the device is paired with the Apple Watch. |
isReachable | Boolean | If the 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 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 for more infos. |