ios – UIPasteControl Not Firing

0
3
ios – UIPasteControl Not Firing


I’ve an iOS app the place I am making an attempt to stick one thing beforehand copied to the consumer’s UIPasteboard. I got here throughout the UIPasteControl as an possibility for a consumer to faucet to silently paste with out having the immediate “Permit Paste” pop up.

For some motive, regardless of having what seemingly is the right configurations for the UIPasteControl, on testing a faucet, nothing is known as. I anticipated override func paste(itemProviders: [NSItemProvider]) to fireside, nevertheless it doesn’t.

Any assist can be appreciated as there does not appear to be a lot data wherever concerning UIPasteControl.

import UIKit
import UniformTypeIdentifiers

class ViewController: UIViewController {
non-public let pasteControl = UIPasteControl()

override func viewDidLoad() {
    tremendous.viewDidLoad()

    view.backgroundColor = .systemBackground

    pasteControl.goal = 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 supplier in itemProviders {
            if supplier.hasItemConformingToTypeIdentifier(UTType.url.identifier) {
                supplier.loadObject(ofClass: URL.self) { [weak self] studying, _ in
                    guard let url = studying as? URL else { return }
                    print(url)
                }
            }
            else if supplier.hasItemConformingToTypeIdentifier(UTType.plainText.identifier) {
                supplier.loadObject(ofClass: NSString.self) { [weak self] studying, _ in
                    guard let nsstr = studying as? NSString else { return }
                    let str = nsstr as String
                    if let url = URL(string: str) {
                        print(url)
                    }
                }
            }
        }
    }
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here