UIPasteControl Not Recognizing Tap

I have an iOS app where I'm trying to paste something previously copied to the user's UIPasteboard. I came across the UIPasteControl as an option for a user to tap to silently paste without having the prompt "Allow Paste" pop up.

For some reason, despite having what seemingly is the correct configurations for the UIPasteControl, on testing a tap, nothing is called. I expected override func paste(itemProviders: [NSItemProvider]) to fire, but it does not.

Any help would be appreciated as there doesn't seem to be much info anywhere regarding UIPasteControl.

import UniformTypeIdentifiers

class ViewController: UIViewController {
private let pasteControl = UIPasteControl()

override func viewDidLoad() {
    super.viewDidLoad()

    view.backgroundColor = .systemBackground

    pasteControl.target = self
    pasteConfiguration = UIPasteConfiguration(acceptableTypeIdentifiers: [
         UTType.text.identifier,
         UTType.url.identifier,
         UTType.plainText.identifier
     ])

    view.addSubview(pasteControl)
    pasteControl.translatesAutoresizingMaskIntoConstraints = false
    NSLayoutConstraint.activate([
        pasteControl.centerXAnchor.constraint(equalTo: view.centerXAnchor),
        pasteControl.centerYAnchor.constraint(equalTo: view.centerYAnchor),
    ])
}
}

extension ViewController {
override func paste(itemProviders: [NSItemProvider]) {
        for provider in itemProviders {
            if provider.hasItemConformingToTypeIdentifier(UTType.url.identifier) {
                provider.loadObject(ofClass: URL.self) { [weak self] reading, _ in
                    guard let url = reading as? URL else { return }
                    print(url)
                }
            }
            else if provider.hasItemConformingToTypeIdentifier(UTType.plainText.identifier) {
                provider.loadObject(ofClass: NSString.self) { [weak self] reading, _ in
                    guard let nsstr = reading as? NSString else { return }
                    let str = nsstr as String
                    if let url = URL(string: str) {
                        print(url)
                    }
                }
            }
        }
    }
}

Tried setting pasteControl's pastConfiguration, and got the same result..

  pasteControl.pasteConfiguration = UIPasteConfiguration(
  acceptableTypeIdentifiers: [
    UTType.text.identifier,
    UTType.url.identifier,
    UTType.plainText.identifier
  ]
)

@ccynn22 Give this a try:

import UIKit
import UniformTypeIdentifiers

class ViewController: UIViewController {
    private lazy var pasteControl: UIPasteControl = {
        let config = UIPasteControl.Configuration()
        config.displayMode = .iconAndLabel
        config.cornerStyle = .medium
        config.baseForegroundColor = .systemBlue
        config.baseBackgroundColor = .systemBackground
        
        let control = UIPasteControl(configuration: config)
        control.target = self
        control.translatesAutoresizingMaskIntoConstraints = false
        return control
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupPasteControl()
    }
    
    private func setupPasteControl() {
        view.addSubview(pasteControl)
        
        NSLayoutConstraint.activate([
            pasteControl.centerXAnchor.constraint(equalTo: view.centerXAnchor),
            pasteControl.centerYAnchor.constraint(equalTo: view.centerYAnchor)
        ])
    }
}

extension ViewController {
    // types of content your app can accept
    override var pasteConfiguration: UIPasteConfiguration? {
        get {
            return UIPasteConfiguration(acceptableTypeIdentifiers: [
                UTType.plainText.identifier,
                UTType.image.identifier
            ])
        }
        set {}
    }
    
    override func paste(itemProviders: [NSItemProvider]) {
        for itemProvider in itemProviders {
            if itemProvider.canLoadObject(ofClass: NSString.self) {
                itemProvider.loadObject(ofClass: NSString.self) { [weak self] (string, error) in
                    if let pastedString = string as? String {
                        DispatchQueue.main.async {
                            self?.handlePastedText(pastedString)
                        }
                    }
                }
            } else if itemProvider.canLoadObject(ofClass: UIImage.self) {
                itemProvider.loadObject(ofClass: UIImage.self) { [weak self] (image, error) in
                    if let pastedImage = image as? UIImage {
                        DispatchQueue.main.async {
                            self?.handlePastedImage(pastedImage)
                        }
                    }
                }
            }
        }
    }
    
    private func handlePastedText(_ text: String) {
        print("Pasted text: \(text)")
    }
    
    private func handlePastedImage(_ image: UIImage) {
        print("Pasted image: \(image)")
    }
}

UIPasteControl Not Recognizing Tap
 
 
Q