I am trying to create a copy button for an iOS Widget using AppIntent
.
Here is my code:
struct CopyTextIntent: AppIntent {
static var title: LocalizedStringResource = "Copy Resource"
static var isDiscoverable: Bool { false }
var resource: String
init(resource: String) {
self.resource = resource
}
init() {
self.resource = "'_'/"
}
func perform() async throws -> some ReturnsValue<String> {
let pasteboard = UIPasteboard.general
pasteboard.string = resource
return .result(value: resource)
}
}
When I use this on my widget and click on it, it either silently fails or throws this error:
saving pasteboard failed with error: Error Domain=PBErrorDomain Code=11 “The pasteboard name com.apple.UIKit.pboard.general is not valid.” UserInfo={NSLocalizedDescription=The pasteboard name com.apple.UIKit.pboard.general is not valid.}
I am trying to copy my widget’s string to UIPasteboard
but it isn’t working.