Programmatically examining pasteboard clears Universal Clipboard contents

Originator:robotspacer
Number:rdar://28839713 Date Originated:19-Oct-2016 01:00 AM
Status:Open Resolved:24-Oct-2016 04:06 PM
Product:iOS SDK Product Version:iOS 10.1 beta 3 (14B72)
Classification:Serious Bug Reproducible:Always
 
Summary:
My app Deliveries includes a feature that I've seen in many other apps: it examines the pasteboard contents, and if the contents are something the user might want to use in the app, a dialog pops up to make the process faster.

Unfortunately the magic of Universal Clipboard is a bit too magical, and causes some problems with features like this that are impossible to work around. In order to determine whether it's appropriate to pop up a dialog, my app needs to examine the contents of the clipboard—for example by getting the value of [UIPasteboard generalPasteboard].URL or [UIPasteboard generalPasteboard].string. Since my app is a package tracking app, it then examines those contents to see if they look like a tracking URL or tracking number.

If the contents of the clipboard came from a Universal Clipboard handoff, the clipboard will be empty shortly after my app examines it. If there was a tracking URL or tracking number on the clipboard, AND the user taps on the dialog that appears to add it automatically, this isn't a problem.

However there are many other likely scenarios:

- There was tracking information on the clipboard, but my app didn't recognize it, or wasn't confident enough about what it was. No dialog is displayed, and the clipboard contents are lost.

- There was tracking information on the clipboard, and it was recognized, but the user didn't see the message that appeared, or accidentally dismissed it. The contents are lost.

- There was no tracking information on the clipboard, but there was some content the user was trying to paste into my app (or even in another app after they were done with mine). Again, those contents are lost.

I don't see any reasonable way to work around this. The new hasStrings and hasURLs properties are helpful, but I can't assume any string or URL is valid tracking data. I would settle for not examining the contents when it's Universal Clipboard data, but as far as I can tell that's not even possible. I could add the data back to the clipboard after examining it, but that seems like a terrible idea that's sure to cause unexpected and problematic side effects. If I remove this feature many of my users will be upset.

Steps to Reproduce:
1. Make sure you have two devices logged into the same iCloud account so Universal Clipboard can work between them.
2. Download "Deliveries: a package tracker" (or another app that programmatically examines the pasteboard contents) onto device A.
3. Copy some text on device B.
4. Return to device A and open the app. In the case of Deliveries, the pasteboard contents are examined when the app becomes active.
5. Wait a second or two and then attempt to paste the pasteboard contents.

Expected Results:
The contents you copied on device A should be pasted.

Actual Results:
The pasteboard is empty.

Version:
iOS 10.1 beta 3 (14B72)

Notes:
If you'd like to see what happens when Deliveries does recognize a tracking number on the clipboard, try 1Z1111111111111111.

Configuration:
iPhone 6s, AT&T, 128GB

Attachments:

Comments

Resolved

With the final versions of macOS 10.12.1 and iOS 10.1 I am no longer able to reproduce this issue.

By robotspacer at Oct. 24, 2016, 8:06 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!