Using the UIPasteControl

Hello 👋🏽

I am a new iOS developer and I am having a hard time understanding the behavior of the new UIPasteControl to avoid showing the system prompt.

Does anyone has any example code I could look at to understand the behavior. Idk how to set the target of the button to the general pasteboard.

also I am using objective-c . thanks cristian

  • Ok so after reading a bit more I understood that the target has to be a UIResponder which could be a UIViewController.

    I am running into another issue now that the button is disabled. It’s grayed out for some reason. So when I press on it, no events are passed to the target. Any ideas why it is disabled?

Add a Comment

Replies

Thanks for interacting with my baby!

To enable UIPasteControl, its target needs to be set to an object that conforms to UIPasteConfigurationSupporting, so typically a UIResponder like UIViewController or UIView. Then you would ensure the object's pasteConfiguration is set to allow the types you want to paste e.g.

self.pasteConfiguration = [[UIPasteConfiguration alloc] initWithTypeIdentifiersForAcceptingClass:[UIImage class]];

(Alternatively, you can override canPasteItemProviders: if that suits your design better.)

Finally, there must be content on the pasteboard compatible with these type identifiers.

The big win here is you don't have to write special code to check whether the pasteboard has compatible types and manually enable/disable the control. You just have to set it up correctly as above.

glow

Add a Comment

Hello,

I like this new UIPasteControl a lot, however, I've noticed that it can often stay "active" even though there is nothing that can be pasted regardless of the target ... I'm not sure if this is a bigger Apple bug but I get the following error in the override func paste(itemProviders: [NSItemProvider]):

[Pasteboard] ...requesting item failed with error: Error Domain=PBErrorDomain Code=13 "Operation not authorized." UserInfo={NSLocalizedDescription=Operation not authorized.}

What is going on here?

The UIPasteControl indicates that it can be pressed since it is not grayed out but when pressed, nothing is pasted to the `UITextField... it results in the above error.

I've even tried when the target is a UIView/UIViewController and overriding canPasteItemProviders:... same result.

Quitting the app and starting again produces the same results.

Note: When it's in this state, I've noticed that you can not directly paste in textfields of other apps, etc.

Any help here would be great because I would like to use this feature but it's currently making my app feel buggy. :)

  • I see the same thing and have the same concerns.

Add a Comment

Hi,

Is there a way programatically i can check if UIPastecontrol is disabled or enabled as in grayed out or not?

Hello, Have the same issue. I added UIPasteControl to my UIViewController. I copy content from another application, wait 15 minutes and after that I press to UIPasteControl and nothing happens. But pasteboard has content, I see it in another application. I call UIPasteboard.general.detectValues(for: patterns) and see same errors in console: Error Domain=PBErrorDomain Code=13 "Operation not authorized." UserInfo={NSLocalizedDescription=Operation not authorized.}

Is there a way to know in advance whether there is content in the pasteboard before showing the UIPasteControl?