Apps that try to access the contents of the pasteboard cause a system prompt to appear asking the user
"AppName" would like to paste from "OtherAppName"
Do you want to allow this?
Don't Allow Paste
Allow Paste
This prompt does not appear if you implement a UIPasteControl and the user taps it to signal intent to paste, but this control cannot be placed into a UIMenu. I read this could be achieved with UIAction.Identifiers like .paste or .newFromPasteboard but the prompt still appears with the following code. What's the trick?
override func viewDidLoad() {
super.viewDidLoad()
title = "TestPaste"
view.backgroundColor = .systemBackground
let imageView = UIImageView()
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.contentMode = .scaleAspectFit
imageView.clipsToBounds = true
view.addSubview(imageView)
NSLayoutConstraint.activate([
imageView.topAnchor.constraint(equalTo: view.topAnchor),
imageView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
imageView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
imageView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
])
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Add", image: UIImage(systemName: "plus"), menu: UIMenu(children: [
UIAction(identifier: .paste) { _ in
imageView.image = UIPasteboard.general.image
}
]))
}