Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-9222] iOS: UI.Clipboard hasData and getData cause exceptions

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2012-06-02T22:26:55.000+0000
Affected Version/sRelease 2.0.1
Fix Version/sRelease 2.1.0, Sprint 2012-11 API
ComponentsiOS
Labelsmodule_clipboard, qe-testadded
ReporterPaul Dowsett
AssigneeArthur Evans
Created2012-05-24T07:54:18.000+0000
Updated2013-11-06T19:03:36.000+0000

Description

Problem

The hasData and getData methods of [Titanium.UI.Clipboard](http://docs.appcelerator.com/titanium/2.0/index.html#!/api/Titanium.UI.Clipboard) fail and cause exceptions. See the test case below, and the source at [TiUIClipboardProxy.m](https://github.com/appcelerator/titanium_mobile/blob/master/iphone/Classes/TiUIClipboardProxy.m).

Test case

Titanium.UI.setBackgroundColor('#000');

Ti.API.log('Deleting all text in Clipboard');
Ti.UI.Clipboard.clearText();
Ti.API.log('Clipboard.getText(): ' + Ti.UI.Clipboard.getText()); // returns undefined when empty
Ti.API.log('Set text Clipboard to hello');
Ti.UI.Clipboard.setText('hello');
Ti.API.log('Clipboard.hasText(), should be true: ' + Ti.UI.Clipboard.hasText()); // hasText() returns 0 or 1 instead of boolean
Ti.API.log('Clipboard.getText(), should be hello: ' + Ti.UI.Clipboard.getText());


if (Ti.UI.iOS){
	Ti.API.log('Deleting all data in Clipboard');
	Ti.UI.Clipboard.clearData();
	Ti.API.log('Adding 3 URLs to Clipboard');
	Ti.UI.Clipboard.setData('text/uri-list', 'http://www.appcelerator.com/');
	Ti.UI.Clipboard.setData('text/uri-list', 'http://developer.android.com/');
	Ti.UI.Clipboard.setData('text/uri-list', 'https://developer.apple.com/');
	Ti.API.log('Getting URLs from Clipboard');
	Ti.API.log('Does Clipboard contain data of type text/uri-list?): ' + Ti.UI.Clipboard.hasData('text/uri-list')); // causes exception
	Ti.UI.Clipboard.getData('text/uri-list'); // causes exception
	
	Ti.API.log('Does Clipboard contain data of type image?): ' + Ti.UI.Clipboard.hasData('image'));  // causes exception
	Ti.UI.Clipboard.getData('image'); // causes exception
}

Logs

[ERROR] Invalid type passed to function. expected: NSString, was: __NSArrayM in -TiUIClipboardProxy getData:

[ERROR] Script Error = Invalid type passed to function. expected: NSString, was: __NSArrayM in -TiUIClipboardProxy getData: at app.js (line 3307).

Discussions

There are no reports in the Q&A that suggest that anyone has successfully used these methods. If it does function as expected, we will need to document this accordingly with some examples.

Comments

  1. Arthur Evans 2012-05-27

    Addressed in PR: https://github.com/appcelerator/titanium_mobile/pull/2283
  2. Max Stepanov 2012-05-29

    PR merged https://github.com/appcelerator/titanium_mobile/pull/2283
  3. Paul Dowsett 2012-05-29

    APIDOC fixed in https://github.com/appcelerator/titanium_mobile/pull/2269
  4. Wilson Luu 2012-06-05

    Closing bug. Verified fix on: SDK build: 2.1.0.v20120604151821 Titanium Studio, build: 2.0.2.201205311912 xcode: 4.3.2 Device: iphone simulator (5.0), iphone 4s verizon (5.0.1)
  5. Shameer Jan 2013-11-06

    Anvil testcase PR https://github.com/appcelerator/titanium_mobile/pull/4731

JSON Source