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.
Addressed in PR: https://github.com/appcelerator/titanium_mobile/pull/2283
PR merged https://github.com/appcelerator/titanium_mobile/pull/2283
APIDOC fixed in https://github.com/appcelerator/titanium_mobile/pull/2269
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)
Anvil testcase PR https://github.com/appcelerator/titanium_mobile/pull/4731