[TIMOB-23797] iOS: Improve Pasteboard support
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2016-08-30T21:47:10.000+0000 |
Affected Version/s | Release 5.5.0 |
Fix Version/s | Release 5.5.0 |
Components | iOS |
Labels | qe-5.5.0 |
Reporter | Eric Wieber |
Assignee | Hans Knöchel |
Created | 2016-08-22T05:18:41.000+0000 |
Updated | 2016-09-06T21:58:04.000+0000 |
Description
There are several features of Pasteboards described in https://developer.apple.com/reference/uikit/uipasteboard that we currently do not support: Named pasteboards (TIMOB-23799), localOnly, expiration time/date, etc.
Ideally, we would support these features (and avoid the deprecations introduced with iOS 10).
Good one. Named pasteboards are a big thing and need further investigation to be integrated in the existing API's, so I would like to get that in a new ticket like "iOS: Support named pasteboards". For the new
setItems
method that also takesUIPasteboardOption
options, I just implemented the new API (for 6.1.0). PR coming shortly.PR (master): https://github.com/appcelerator/titanium_mobile/pull/8247 PR (5_5_X): https://github.com/appcelerator/titanium_mobile/pull/8290 PR (6_0_X): https://github.com/appcelerator/titanium_mobile/pull/8289 Demo:
[~hansknoechel], sounds good. Created TIMOB-23799 for Named Pasteboard support.
The
getItems()
method is throwing an error when there are no items in the Pasteboard:*Steps to reproduce issue* 1. Create a new project 2. Add the below lines to the code, preferably on a button press:
Ti.UI.Clipboard.clearData();
alert(Ti.UI.Clipboard.getItems());
3. Run the project and press the button or call the methods *Expected results*getItems()
returns an empty array, without error *Actual results* The above error is thrown *Notes* This is stated in the docs forsetItems()
, but is there a way we can handle it better? Perhaps checkingnumberOfItems
and using that to make sure the Pasteboard is not empty first? Although a runtime error is thrown, you can see an empty array returned fromgetItems()
if you dismiss the error and call it again. However, If you clear the data withclearData()
and then callgetItems()
too many times (sometimes 2), then the app will crash with the below error:[~ewieber] As far as I understood, the iOS 10 method
setItems
persists the item at a different internal location to enable options like the expire- and localOnly configuration. So usingclearData
will only clear the items that have been set with the known methods: {quote} Starting in iOS 10 there is a new Handoff feature which allows the general pasteboard contents to automatically transfer between devices. You can control Handoff behavior for pasteboard contents, and can set a pasteboard to expire, by using thesetItems(_:options:\)
method, as follows: To exclude a pasteboard from Handoff, call thesetItems(_:options:\)
method with the localOnly option. To indicate an expiration time and date for copied data, call thesetItems(_:options:\)
method with the expirationDate option. At the time and date that you set, the system removes the pasteboard items from the pasteboard. {quote} SosetItems
is primary for enabling handoff with those items andclearData
is specific to the system-wide pasteboard. See the [official docs](https://developer.apple.com/reference/uikit/uipasteboard).I see, but there is either some connection between the two or there is an issue with calling
getItems
on an empty Pasteboard, hence the crash. What are your thoughts on usingnumberOfItems
to make sure that the Pasteboard has >0 items before calling\[\[\[UIPasteboard generalPasteboard\] items\] retain\]
?Well, the number of items is > 0, but those items are invalid from previous
setItems
calls that had an invalid mime-type specified. The whole ticket should have gone into 6.1.0. But for now, I would suggest an improvement-ticket to summarize your finding that can go into 6.0.0, so I have more time to investigate the different use-cases you want.TIMOB-23858 created to continue the discussion/investigation on the
clearData
andgetItems
issueSince TIMOB-23799, TIMOB-23857, and TIMOB-23858 cover the issue above and the implementation of other APIs, this can be considered done. Tested using: MacOS 10.12 (16A239m) Studio 4.7.1.201608190732 Ti SDK 5.5.0.v20160904203801 Appc NPM 4.2.7 Appc CLI 5.5.0-5 Alloy 1.9.1 Xcode 8.0 (8S201h) I am now able to get and set items on Pasteboards, using the
localOnly
and expiration date properties, without error. Tested using the provided samples as well as my own test apps that get/set multiple items on a Pasteboard and use one or both of the localOnly and expiration date properties.