How to limit SwiftUI PasteButton for custom URLs?

For GNU Taler, we defined a custom URL scheme: "taler://".

We want to have a SwiftUI PasteButton in our app which is only active/enabled when the user copied a talerURI, but not for other URIs (such as https:// or mailto://). Currently we use

  PasteButton(supportedContentTypes: [.url]) { providers in

which works, but is also enabled when the copied text is some other URI, not only for "taler://".

Can we define a UTType ".taler" for PasteButton to check whether the pasteBoard has indeed a talerURI? How?

PasteButton's supportedContentTypes matches on the type an item was written with, not on what the item actually contains.

  • If an app you own does the copying, you can declare an exported type and define a transfer representation that vends both your custom type and .url. You can then handle this in your app when you receive an item that conformance to that content type.

  • If the copying is done by a system application or another third-party app, you can validate the content directly inside the PasteButton closure instead.

The copying is always done by Mail.app or Messages.app or 3rd party messengers. Since the PasteButton closure is called after the user tapped on Paste, which of course is only possible if the PasteButton is enabled, we cannot disable it. So the user taps the PasteButton, and then we can examine the pasteBoard, and show an annoying alert that there is no talerURI...

The user experience would be way better if we already knew that the pasteBoard contains a talerURI, and only then enabled the PasteButton.

Feature request: add an optional filter for URL schemes, so the app can not only ask if there is some kind of URL in the pasteBoard, but also which kind. Some apps might only want "https:" URLs, others want only "mailto:", and we want only "taler:".

How to limit SwiftUI PasteButton for custom URLs?
 
 
Q