ios – PasteButton shows “Allow Paste” prompt


I added a PasteButton to my SwiftUI app, but it still shows the “Allow Paste” prompt when tapped. After fighting this problem for half a day without success, I created a new SwiftUI app in Xcode and added this code from PasteButton documentation:

@State private var pastedText: String = ""

var body: some View {
    HStack {
        PasteButton(payloadType: String.self) { strings in
            pastedText = strings[0]
        }
        Divider()
        Text(pastedText)
        Spacer()
    }
}

This works as expected in the Simulator: when I copy text, the button looks enabled and there is no prompt when I tap it – the text is pasted directly. When I copy something else, say an image, the button looks disabled.

When I run this sample app on a device and copy text, the button still looks disabled. When I tap it, the prompt “Allow Paste” appears. If I tap “Allow”, the text is pasted. What am I doing wrong?

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img