Titanium.UI.Clipboard
> Titanium.UI.Clipboard

A module used for accessing clipboard data.

The Clipboard is a temporary data store, used to save a single item of data that may then be accessed by the user using UI copy and paste interactions within an app or between apps.

On iOS, the module's *Data() methods enable multiple representations of the same data item to be stored together with their respective MIME type to describe their format. For example, 'text' and 'text/plain' for text, and 'image/jpg' and 'image/png' for an image.

When working with text, either the *Data() methods may be used with a 'text/plain' type, or the *Text() methods without the need to specify the type.

Android currently only supports text type of data to be stored.

Clipboard Data Types

The *Text() methods are equivalent to calling *Data() with a 'text' or 'text/plain' type. These work with plain Unicode strings.

An image is stored using the 'image' type, or an explicit image MIME type, and is returned as a Titanium.Blob (binary) type.

A URL is stored with the 'url' or 'text/uri-list' type, and is returned as a string.

Any data type that is specified but not correctly mapped to a clipboard type by the system is retrieved as a Titanium.Blob type.

Examples

Copy Text to the Clipboard

Clear the clipboard and output the resulting empty clipboard to console.

Then, store the string, "hello", to the clipboard and output it from the clipboard to the console.

Ti.API.info('Deleting all text in Clipboard');
Ti.UI.Clipboard.clearText();
Ti.API.info('Clipboard.getText(): ' + Ti.UI.Clipboard.getText()); // returns empty string on Android and undefined on iOS
Ti.API.info('Set text Clipboard to hello');
Ti.UI.Clipboard.setText('hello');
Ti.API.info('Clipboard.hasText(), should be true: ' + Ti.UI.Clipboard.hasText()); // returns true on Android and 1 on iOS
Ti.API.info('Clipboard.getText(), should be hello: ' + Ti.UI.Clipboard.getText());

Set multiple items including privacy options (iOS 10 and later)

The items are represented as an array that holds different objects of key-value items. Optionally, you can set privacy options described in Ti.UI.CLIPBOARD_OPTION_*. Note that you can not have the same two keys in one object and the key must match a valid mime-type. If no valid mime-type is specified

var win = Ti.UI.createWindow({
    backgroundColor : "#fff"
});

var btn1 = Ti.UI.createButton({
    title : "Set clipboard items",
    top: 40
});

var btn2 = Ti.UI.createButton({
    title : "Get clipboard items",
    top: 80
});

btn1.addEventListener("click", function() {
    var localOnly = Ti.UI.CLIPBOARD_OPTION_LOCAL_ONLY;
    var expirationDate = Ti.UI.CLIPBOARD_OPTION_EXPIRATION_DATE;

    Ti.UI.Clipboard.setItems({
        items: [{
            "text/plain": "John",
        },{
            "text/plain": "Doe"
        }],
        options: {
            localOnly: true,
            expirationDate: new Date(2020, 04, 20)
        }
    });
});

btn2.addEventListener("click", function() {
    alert(Ti.UI.Clipboard.getItems());
});

win.add(btn1);
win.add(btn2);
win.open();

Use of named clipboard in iOS

var clipboard1 = Ti.UI.createClipboard({
    name : 'myClipboard',
    allowCreation : true
});
clipboard1.setText('hello');

var clipboard2 = Ti.UI.createClipboard({
    name : 'myClipboard'
});

Ti.API.info('Clipboard name is: ' + clipboard1.name);
Ti.API.info('Both clipboards should return "hello"');
Ti.API.info('clipboard1.getText() ' + clipboard1.getText());
Ti.API.info('clipboard2.getText() ' + clipboard2.getText());

Use of unique named clipboard in iOS

var clipboard = Ti.UI.createClipboard({
    unique : true
});
clipboard.setText('hello');

Ti.API.info('clipboard name is: ' + clipboard.name);
Ti.API.info('clipboard.getText() ' + clipboard.getText());
  • 1.5
  • 1.5
  • 1.5
Defined By

Properties

Titanium.UI.Clipboard
allowCreation : BooleanCreation-Only

Create a clipboard identified by name if it doesn't exist.

Create a clipboard identified by name if it doesn't exist.

If "create" is false, it will return the existing named clipboard but will not create new one. If "create" is true, it will return the existing clipboard (if exists). Otherwise it will create new clipboard with given name.

  • 6.1.0
  • 6.1.0
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

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.UI.Clipboard
name : StringCreation-Only

Create a new named clipboard.

Create a new named clipboard.

Create a new clipboard with a given name. See the example on how to use this.

  • 6.1.0
  • 6.1.0
Titanium.UI.Clipboard
unique : BooleanCreation-Only

Create a new clipboard identified by a unique system-generated name.

Create a new clipboard identified by a unique system-generated name.

Create a new clipboard identified by a unique system-generated name. See the example on how to use this.

  • 6.1.0
  • 6.1.0
Defined By

Methods

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.UI.Clipboard
( [type] )
Deletes data of the specified MIME type stored in the clipboard. ...

Deletes data of the specified MIME type stored in the clipboard. If MIME type omitted, all data is deleted.

On Android, identical to clearText method.

Parameters

  • type : String (optional)

    MIME type. Ignored on Android.

Returns

  • void
Titanium.UI.Clipboard
( )
Deletes all text data stored in the clipboard. ...

Deletes all text data stored in the clipboard.

This method deletes any data saved using the setText method, or that has a text or text/plain MIME type.

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.UI.Clipboard
( ) : Boolean
Gets the value of the allowCreation property. ...

Gets the value of the allowCreation property.

  • 6.1.0
  • 6.1.0

Returns

  • Boolean
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.UI.Clipboard
( type ) : String/Titanium.Blob
Gets data of the specified MIME type stored in the clipboard. ...

Gets data of the specified MIME type stored in the clipboard.

Parameters

  • type : String

    MIME type. Must be text type on Android.

Returns

Titanium.UI.Clipboard
( ) : Dictionary[]
Gets the items that have been specified earlier using setItems. ...

Gets the items that have been specified earlier using setItems.

Requires: iOS 10.0 and later

  • 5.5.0
  • 5.5.0

Returns

Gets the value of the lifecycleContainer property. ...

Gets the value of the lifecycleContainer property.

  • 3.6.0

Returns

Titanium.UI.Clipboard
( ) : String
Gets the value of the name property. ...

Gets the value of the name property.

  • 6.1.0
  • 6.1.0

Returns

  • String
Titanium.UI.Clipboard
( ) : String
Gets text data stored in the clipboard. ...

Gets text data stored in the clipboard.

Returns

  • String
Titanium.UI.Clipboard
( ) : Boolean
Gets the value of the unique property. ...

Gets the value of the unique property.

  • 6.1.0
  • 6.1.0

Returns

  • Boolean
Titanium.UI.Clipboard
( ) : Boolean
Indicates whether any colors are stored in the clipboard. ...

Indicates whether any colors are stored in the clipboard.

Requires: iOS 10.0 and later

  • 6.0.0
  • 6.0.0

Returns

  • Boolean
Titanium.UI.Clipboard
( type ) : Boolean
Indicates whether any data of the specified MIME type is stored in the clipboard. ...

Indicates whether any data of the specified MIME type is stored in the clipboard.

Parameters

  • type : String

    MIME type. Must be text type on Android.

Returns

  • Boolean
Titanium.UI.Clipboard
( ) : Boolean
Indicates whether any images are stored in the clipboard. ...

Indicates whether any images are stored in the clipboard.

Requires: iOS 10.0 and later

  • 6.0.0
  • 6.0.0

Returns

  • Boolean
Titanium.UI.Clipboard
( ) : Boolean
Indicates whether any text data is stored in the clipboard. ...

Indicates whether any text data is stored in the clipboard.

Returns

  • Boolean
Titanium.UI.Clipboard
( ) : Boolean
Indicates whether any URLs are stored in the clipboard. ...

Indicates whether any URLs are stored in the clipboard.

Requires: iOS 10.0 and later

  • 6.0.0
  • 6.0.0

Returns

  • Boolean
Titanium.UI.Clipboard
( )
Removes the clipboard. ...

Removes the clipboard.

  • 6.1.0
  • 6.1.0

Returns

  • void
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.UI.Clipboard
( allowCreation )
Sets the value of the allowCreation property. ...

Sets the value of the allowCreation property.

  • 6.1.0
  • 6.1.0

Parameters

  • allowCreation : Boolean

    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.UI.Clipboard
( type, data )
Stores data of the specified MIME type in the clipboard. ...

Stores data of the specified MIME type in the clipboard.

This method will overwrite any existing data for the specified MIME type.

Note that the clipboard is intended to store only one item of data at a time. This method enables different representations/formats of a data item to be saved.

Parameters

  • type : String

    MIME type. Must be text type on Android.

  • data : Object

    New item of data.

Returns

  • void
Titanium.UI.Clipboard
( items )
Adds an array of items to a clipboard, and sets privacy options for all included items. ...

Adds an array of items to a clipboard, and sets privacy options for all included items.

Requires: iOS 10.0 and later

You can pass multiple options to the options object. Note that this API is mime-type based. The key must be a valid mime-type and the value must be the value that matches the given mime-type. If no valid mime-type is provided a a key, receiving items with getItems will crash the app. See the below example for more information on the usage.

  • 5.5.0
  • 5.5.0

Parameters

  • items : ClipboardItemsType

    An array of key-value items to add to the clipboard. The key must a valid mime-type matching the mime-type of the value.

Returns

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

Sets the value of the lifecycleContainer property.

  • 3.6.0

Parameters

Returns

  • void
Titanium.UI.Clipboard
( name )
Sets the value of the name property. ...

Sets the value of the name property.

  • 6.1.0
  • 6.1.0

Parameters

  • name : String

    New value for the property.

Returns

  • void
Titanium.UI.Clipboard
( text )
Stores text data in the clipboard. ...

Stores text data in the clipboard.

This method will overwrite any existing text data.

Parameters

  • text : String

    New item of data.

Returns

  • void
Titanium.UI.Clipboard
( unique )
Sets the value of the unique property. ...

Sets the value of the unique property.

  • 6.1.0
  • 6.1.0

Parameters

  • unique : Boolean

    New value for the property.

Returns

  • void