UIPasteboard bug?

I was trying to use UIPasteboard.general.url to get some content, and I found that UIPasteboard.general.string could get the Universal Clipboard (other  devices' clipboard like Mac's and iPad's) while UIPasteboard.general.url could only get the local Clipboard.

Below is a simply way to reproduce (in SwiftUI)
Code Block swift
Button(Text("getURL")){
print("url is \(UIPasteboard.general.url)")
print("string is \(UIPasteboard.general.string)")
}

  1. First you copy this link (actually any url string is OK) in Mac http://pic1.win4000.com/wallpaper/2019-08-05/5d47e530bcf01.jpg . And click the above button in your iOS device, you'll see something like this in your log

Code Block
url is nil
string is Optional("http://pic1.win4000.com/wallpaper/2019-08-05/5d47e530bcf01.jpg")


2. Second you simply paste it into your iOS device(Universal Clipboard on) and copy it so that your local pasteboard have this content. And then click the above button in your iOS device, you'll see something like this in your log
Code Block
url is Optional("http://pic1.win4000.com/wallpaper/2019-08-05/5d47e530bcf01.jpg")
string is Optional("http://pic1.win4000.com/wallpaper/2019-08-05/5d47e530bcf01.jpg")


I found that what matters is how the "client" app creates the item on the pasteboard and what kind of objects it includes in the item.

For example, with Google Chrome on the Mac (version 85), if you highlight the URL of the current page in the address bar and copy that text to the clipboard, my iPhone (iOS 14) will just show the pasteboard item as having public.text and public.utf8-plain-text (and com.apple.is-remote-clipboard). In that case, of course, the iPhone UIPasteboard.general will show that it .hasStrings but not .hasURLs.

But if I "right-click" a link in Safari on the Mac and choose "Copy Link", then Safari will create a pasteboard item with text and also with public.url. These objects show up on the iPhone, and thus UIPasteboard.general.hasURLs == true.

Have you found a way to force a url written to the clipboard to be seen as a url? I've been trying to write to the clipboard and then check if the url is on the clipboard by first using hasURLs but it keeps returning false. I get the same public.text and public.utf8-plain-text types when I'm trying on my device.

UIPasteboard bug?
 
 
Q