The UserActivity module is used to enable device Handoff and to create User Activities.
A UserActivity object requires the activityType
property to be specified at creation time.
Additional properties can be set either at creation or set individually after creation.
Handoff will not work in the simulator. You must build and run on a compatible device.
Handoff functionality depends on a few things:
Make sure you have two Handoff compatible devices running iOS 8 or later that are logged onto the same iCloud account.
The following example demonstrates how to create a new UserActivity and mark the activity as the current activity Handoff should be using when switching between devices.
It is important to note that all activityTypes must be defined in your tiapp.xml
before this
feature can be supported. It is important to check the supported property on your UserActivity
to ensure the activity created is supported on your device.
var activity = Ti.App.iOS.createUserActivity({
activityType: 'com.setdirection.home',
title: 'activity 1',
userInfo: {
msg: 'hello world'
}
});
if(!activity.isSupported()){
alert('User Activities are not supported on this device!');
} else {
activity.becomeCurrent();
Ti.App.iOS.addEventListener('continueactivity', function(e) {
if (e.activityType === 'com.setdirection.home' && e.userInfo.msg) {
alert(e.userInfo.msg);
}
});
}
<ti:app>
<ios>
<plist>
<dict>
<key>NSUserActivityTypes</key>
<array>
<string>com.setdirection.home</string>
</array>
</dict>
</plist>
</ios>
</ti:app>
Name of the activity type.
Requires: iOS 8.0 and later
Apple recommends using a reverse DNS scheme to name activities in the format: com.
The activity type must also be registered in the ios plist
section of the tiapp.xml
file. Add the NSUserActivityTypes
key and set its value to an array of activity type strings.
<ti:app>
<ios>
<plist>
<dict>
<key>NSUserActivityTypes</key>
<array>
<string>com.fooinc.musicalpedia.playtrack</string>
</array>
</dict>
</plist>
</ios>
</ti:app>
The name of the API that this proxy corresponds to.
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
.
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.
Default: true
Set to true if this user activity should be eligible to be handed off to another device
Requires: iOS 9.0 and later
Default: true
Set to true
if the user activity can be publicly accessed by all iOS users.
Requires: iOS 9.0 and later
Set to true
if this user activity should be eligible for indexing for any user of the application,
on any device, or false
if the activity contains private or sensitive information or which would not be useful to other
users if indexed. You must also set either the requiredUserActivityKeys
or webpageURL
property.
Default: false
Set to true if the user activity should be added to the on-device index.
Requires: iOS 9.0 and later
Default: false
Absolute date after which the activity is no longer eligible to be indexed or handed off.
Requires: iOS 9.0 and later
The date will be a string in the following format: "yyyy-MM-dd'T'HH:mm:ss.SSS'+0000'"
For example, 2015-12-25T23:30:55.978+0000
Default: Determined by iOS
An array of string keywords representing words or phrases that might help the user to find the activity in the application history.
Requires: iOS 9.0 and later
The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.
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.
Set to true everytime you have updated the user activity and need the changes to be saved before handing it off to another device.
Requires: iOS 8.0 and later
An array of String keys from the userInfo property which represent the minimal information about the user activity that should be stored for later restoration.
Requires: iOS 9.0 and later
Determines if user activities are supported (true
) or not (false
) by the device.
deprecated
5.1.0 Use <Titanium.App.iOS.UserActivity.isSupported> instead.
Requires: iOS 8.0 and later
An optional, user-visible title for this activity such as a document name or web page title.
Requires: iOS 8.0 and later
The userInfo dictionary contains application-specific state needed to continue an activity on another device.
Requires: iOS 8.0 and later
When no suitable application is installed on a resuming device and the webpageURL
property is set,
the user activity will instead be continued in a web browser by loading the specified URL.
Requires: iOS 8.0 and later
Only supports the http://
and https://
protocols. Any other protocol will throw an error.
Adds a Titanium.App.iOS.SearchableItemAttributeSet to the user activity.
Requires: iOS 9.0 and later
SearchableItemAttributeSet object that contains the set of properties you want to display for a searchable activity.
Adds the specified callback as an event listener for the named event.
Name of the event.
Callback function to invoke when the event is fired.
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.
A dictionary of properties to apply.
Marks the activity as currently in use by the user.
Requires: iOS 8.0 and later
For example, you should mark the activity associated with the active window as current. A newly created activity is eligible for continuation on another device after the first time it becomes current.
Fires a synthesized event to any registered listeners.
Name of the event.
A dictionary of keys and values to add to the Titanium.Event object sent to the listeners.
Gets the value of the supported property.
deprecated since 5.1.0
Use <Titanium.App.iOS.UserActivity.isSupported> instead.
Invalidates an activity when it is no longer eligible for continuation.
Requires: iOS 8.0 and later
For example, when the window associated with an activity is closed, you should invalidate the activity. An invalid activity cannot become current.
Determines if user activities are supported (true
) or not (false
) by the device.
Requires: iOS 8.0 and later
Returns true
if the device supports user activity.
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 of the event.
Callback function to remove. Must be the same function passed to addEventListener
.
Marks the activity as currently not in use and ineligible to be continued.
Requires: iOS 9.0 and later
Sets the value of the activityType property.
New value for the property.
Sets the value of the bubbleParent property.
New value for the property.
Sets the value of the eligibleForHandoff property.
New value for the property.
Sets the value of the eligibleForPublicIndexing property.
New value for the property.
Sets the value of the eligibleForSearch property.
New value for the property.
Sets the value of the expirationDate property.
New value for the property.
Sets the value of the keywords property.
New value for the property.
Sets the value of the lifecycleContainer property.
New value for the property.
Sets the value of the needsSave property.
New value for the property.
Sets the value of the requiredUserInfoKeys property.
New value for the property.
Sets the value of the supported property.
deprecated since 5.1.0
Use <Titanium.App.iOS.UserActivity.isSupported> instead.
New value for the property.
Sets the value of the title property.
New value for the property.
Sets the value of the userInfo property.
New value for the property.
Sets the value of the webpageURL property.
New value for the property.
Fired when the user activity was continued on another device.
The activityType of the User Activity triggering the event.
The title of the User Activity if defined.
The webpageURL of the User Activity if defined.
Dictionary object containing the userInfo data of the User Activity.
Source object that fired the event.
Name of the event fired.
True if the event will try to bubble up if possible.
Set to true to stop the event from bubbling.
Fired if the activity context needs to be saved before being continued on another device.
To fire the event, set the UserActiviy object's needsSave
property to true
.
The receiver should update the activity with current activity state.
After the event is fired, iOS will reset the needsSave
property to false.
deprecated since 5.2.0
Set the property needsSave
to true everytime you update current activity state instead.
The activityType of the User Activity triggering the event.
The title of the User Activity if defined.
The webpageURL of the User Activity if defined.
Dictionary object containing the userInfo data of the User Activity.
Source object that fired the event.
Name of the event fired.
True if the event will try to bubble up if possible.
Set to true to stop the event from bubbling.