Titanium.App.iOS.UserActivity
> Titanium.App.iOS.UserActivity

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:

  • You must be logged into the same iCloud account on each device you wish to use Handoff.
  • Handoff broadcasts activities via Bluetooth LE signals, so both the broadcasting and receiving devices must have Bluetooth LE 4.0 support.
  • Connect all devices to the same Wi-Fi network.

Make sure you have two Handoff compatible devices running iOS 8 or later that are logged onto the same iCloud account.

Examples

Creating a new UserActivity Example

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.

app.js

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);
        }
    });
}

tiapp.xml

<ti:app>
  <ios>
    <plist>
      <dict>
        <key>NSUserActivityTypes</key>
        <array>
          <string>com.setdirection.home</string>
        </array>
      </dict>
    </plist>
  </ios>
</ti:app>
  • 5.0.0
  • 5.0.0
Defined By

Properties

Titanium.App.iOS.UserActivity
: String
Name of the activity type. ...

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.

tiapp.xml

<ti:app>
  <ios>
    <plist>
      <dict>
        <key>NSUserActivityTypes</key>
        <array>
          <string>com.fooinc.musicalpedia.playtrack</string>
        </array>
      </dict>
    </plist>
  </ios>
</ti:app>
apiName : Stringreadonly

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.

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

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

  • 3.0.0
  • 3.0.0
  • 3.0.0
Titanium.App.iOS.UserActivity
: BooleanCreation-Only
Set to true if this user activity should be eligible to be handed off to another device Requires: iOS 9.0 and l...

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

Titanium.App.iOS.UserActivity
: BooleanCreation-Only
Set to true if the user activity can be publicly accessed by all iOS users. ...

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

Titanium.App.iOS.UserActivity
: BooleanCreation-Only
Set to true if the user activity should be added to the on-device index. ...

Set to true if the user activity should be added to the on-device index.

Requires: iOS 9.0 and later

Default: false

Titanium.App.iOS.UserActivity
: String
Absolute date after which the activity is no longer eligible to be indexed or handed off. ...

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

Titanium.App.iOS.UserActivity
: String[]
An array of string keywords representing words or phrases that might help the user to find the activity in the applic...

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.

  • 3.6.0
Titanium.App.iOS.UserActivity
: Boolean
Set to true everytime you have updated the user activity and need the changes to be saved before handing it off to an...

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

Titanium.App.iOS.UserActivity
: String[]
An array of String keys from the userInfo property which represent the minimal information about the user activity th...

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

Titanium.App.iOS.UserActivity
: Booleandeprecated
Determines if user activities are supported (true) or not (false) by the device. ...

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

Titanium.App.iOS.UserActivity
: String
An optional, user-visible title for this activity such as a document name or web page title. ...

An optional, user-visible title for this activity such as a document name or web page title.

Requires: iOS 8.0 and later

Titanium.App.iOS.UserActivity
: Dictionary
The userInfo dictionary contains application-specific state needed to continue an activity on another device. ...

The userInfo dictionary contains application-specific state needed to continue an activity on another device.

Requires: iOS 8.0 and later

Titanium.App.iOS.UserActivity
: String
When no suitable application is installed on a resuming device and the webpageURL property is set, the user activity ...

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.

Defined By

Methods

Titanium.App.iOS.UserActivity
( contentAttributeSet )
Adds a Titanium.App.iOS.SearchableItemAttributeSet to the user activity. ...

Adds a Titanium.App.iOS.SearchableItemAttributeSet to the user activity.

Requires: iOS 9.0 and later

Parameters

Returns

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

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

Parameters

  • name : String

    Name of the event.

  • callback : Callback<Object>

    Callback function to invoke when the event is fired.

Returns

  • void
Applies the properties to the proxy. ...

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.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Parameters

  • props : Dictionary

    A dictionary of properties to apply.

Returns

  • void
Titanium.App.iOS.UserActivity
( )
Marks the activity as currently in use by the user. ...

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.

Returns

  • void
Fires a synthesized event to any registered listeners. ...

Fires a synthesized event to any registered listeners.

Parameters

  • name : String

    Name of the event.

  • event : Dictionary

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

Returns

  • void
Titanium.App.iOS.UserActivity
( ) : String
Gets the value of the activityType property. ...

Gets the value of the activityType property.

Returns

  • String
Gets the value of the apiName property. ...

Gets the value of the apiName property.

  • 3.2.0
  • 3.2.0
  • 3.2.0

Returns

  • String
Gets the value of the bubbleParent property. ...

Gets the value of the bubbleParent property.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Returns

  • Boolean
Titanium.App.iOS.UserActivity
( ) : Boolean
Gets the value of the eligibleForHandoff property. ...

Gets the value of the eligibleForHandoff property.

Returns

  • Boolean
Titanium.App.iOS.UserActivity
( ) : Boolean
Gets the value of the eligibleForPublicIndexing property. ...

Gets the value of the eligibleForPublicIndexing property.

Returns

  • Boolean
Titanium.App.iOS.UserActivity
( ) : Boolean
Gets the value of the eligibleForSearch property. ...

Gets the value of the eligibleForSearch property.

Returns

  • Boolean
Titanium.App.iOS.UserActivity
( ) : String
Gets the value of the expirationDate property. ...

Gets the value of the expirationDate property.

Returns

  • String
Titanium.App.iOS.UserActivity
( ) : String[]
Gets the value of the keywords property. ...

Gets the value of the keywords property.

Returns

  • String[]
Gets the value of the lifecycleContainer property. ...

Gets the value of the lifecycleContainer property.

  • 3.6.0

Returns

Titanium.App.iOS.UserActivity
( ) : Boolean
Gets the value of the needsSave property. ...

Gets the value of the needsSave property.

Returns

  • Boolean
Titanium.App.iOS.UserActivity
( ) : String[]
Gets the value of the requiredUserInfoKeys property. ...

Gets the value of the requiredUserInfoKeys property.

Returns

  • String[]
Titanium.App.iOS.UserActivity
( ) : Booleandeprecated
Gets the value of the supported property. ...

Gets the value of the supported property.

deprecated since 5.1.0

Use <Titanium.App.iOS.UserActivity.isSupported> instead.

Returns

  • Boolean
Titanium.App.iOS.UserActivity
( ) : String
Gets the value of the title property. ...

Gets the value of the title property.

Returns

  • String
Titanium.App.iOS.UserActivity
( ) : Dictionary
Gets the value of the userInfo property. ...

Gets the value of the userInfo property.

Returns

Titanium.App.iOS.UserActivity
( ) : String
Gets the value of the webpageURL property. ...

Gets the value of the webpageURL property.

Returns

  • String
Titanium.App.iOS.UserActivity
( )
Invalidates an activity when it is no longer eligible for continuation. ...

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.

Returns

  • void
Titanium.App.iOS.UserActivity
( ) : Boolean
Determines if user activities are supported (true) or not (false) by the device. ...

Determines if user activities are supported (true) or not (false) by the device.

Requires: iOS 8.0 and later

Returns

  • Boolean

    Returns true if the device supports user activity.

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

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

  • name : String

    Name of the event.

  • callback : Callback<Object>

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

Returns

  • void
Titanium.App.iOS.UserActivity
( )
Marks the activity as currently not in use and ineligible to be continued. ...

Marks the activity as currently not in use and ineligible to be continued.

Requires: iOS 9.0 and later

Returns

  • void
Titanium.App.iOS.UserActivity
( activityType )
Sets the value of the activityType property. ...

Sets the value of the activityType property.

Parameters

  • activityType : String

    New value for the property.

Returns

  • void
Sets the value of the bubbleParent property. ...

Sets the value of the bubbleParent property.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Parameters

  • bubbleParent : Boolean

    New value for the property.

Returns

  • void
Titanium.App.iOS.UserActivity
( eligibleForHandoff )
Sets the value of the eligibleForHandoff property. ...

Sets the value of the eligibleForHandoff property.

Parameters

  • eligibleForHandoff : Boolean

    New value for the property.

Returns

  • void
Titanium.App.iOS.UserActivity
( eligibleForPublicIndexing )
Sets the value of the eligibleForPublicIndexing property. ...

Sets the value of the eligibleForPublicIndexing property.

Parameters

  • eligibleForPublicIndexing : Boolean

    New value for the property.

Returns

  • void
Titanium.App.iOS.UserActivity
( eligibleForSearch )
Sets the value of the eligibleForSearch property. ...

Sets the value of the eligibleForSearch property.

Parameters

  • eligibleForSearch : Boolean

    New value for the property.

Returns

  • void
Titanium.App.iOS.UserActivity
( expirationDate )
Sets the value of the expirationDate property. ...

Sets the value of the expirationDate property.

Parameters

  • expirationDate : String

    New value for the property.

Returns

  • void
Titanium.App.iOS.UserActivity
( keywords )
Sets the value of the keywords property. ...

Sets the value of the keywords property.

Parameters

  • keywords : Array<String>

    New value for the property.

Returns

  • void
Sets the value of the lifecycleContainer property. ...

Sets the value of the lifecycleContainer property.

  • 3.6.0

Parameters

Returns

  • void
Titanium.App.iOS.UserActivity
( needsSave )
Sets the value of the needsSave property. ...

Sets the value of the needsSave property.

Parameters

  • needsSave : Boolean

    New value for the property.

Returns

  • void
Titanium.App.iOS.UserActivity
( requiredUserInfoKeys )
Sets the value of the requiredUserInfoKeys property. ...

Sets the value of the requiredUserInfoKeys property.

Parameters

  • requiredUserInfoKeys : Array<String>

    New value for the property.

Returns

  • void
Titanium.App.iOS.UserActivity
( supported )deprecated
Sets the value of the supported property. ...

Sets the value of the supported property.

deprecated since 5.1.0

Use <Titanium.App.iOS.UserActivity.isSupported> instead.

Parameters

  • supported : Boolean

    New value for the property.

Returns

  • void
Titanium.App.iOS.UserActivity
( title )
Sets the value of the title property. ...

Sets the value of the title property.

Parameters

  • title : String

    New value for the property.

Returns

  • void
Titanium.App.iOS.UserActivity
( userInfo )
Sets the value of the userInfo property. ...

Sets the value of the userInfo property.

Parameters

Returns

  • void
Titanium.App.iOS.UserActivity
( webpageURL )
Sets the value of the webpageURL property. ...

Sets the value of the webpageURL property.

Parameters

  • webpageURL : String

    New value for the property.

Returns

  • void
Defined By

Events

Titanium.App.iOS.UserActivity
Fired when the user activity was continued on another device. ...

Fired when the user activity was continued on another device.

Properties

  • activityType : String

    The activityType of the User Activity triggering the event.

    •  
    •  
  • title : String

    The title of the User Activity if defined.

    •  
    •  
  • webpageURL : String

    The webpageURL of the User Activity if defined.

    •  
    •  
  • userInfo : Dictionary

    Dictionary object containing the userInfo data of the User Activity.

    •  
    •  
  • source : Object

    Source object that fired the event.

    •  
    •  
    •  
  • type : String

    Name of the event fired.

    •  
    •  
    •  
  • bubbles : Boolean

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

    •  
    •  
    •  
  • cancelBubble : Boolean

    Set to true to stop the event from bubbling.

    •  
    •  
    •  
Titanium.App.iOS.UserActivity
deprecated
Fired if the activity context needs to be saved before being continued on another device. ...

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.

Properties

  • activityType : String

    The activityType of the User Activity triggering the event.

    •  
    •  
  • title : String

    The title of the User Activity if defined.

    •  
    •  
  • webpageURL : String

    The webpageURL of the User Activity if defined.

    •  
    •  
  • userInfo : Dictionary

    Dictionary object containing the userInfo data of the User Activity.

    •  
    •  
  • source : Object

    Source object that fired the event.

    •  
    •  
    •  
  • type : String

    Name of the event fired.

    •  
    •  
    •  
  • bubbles : Boolean

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

    •  
    •  
    •  
  • cancelBubble : Boolean

    Set to true to stop the event from bubbling.

    •  
    •  
    •