iOS Clipboard

Hi all,

Quick question: How does one copy text to the clipboard for iOS? I see that one can do it with the desktop version, but I’m not finding anything for the iOS edition. Hmmm…


Declare Function generalPasteboard Lib "UIKIt" Selector "generalPasteboard" (clsRef As ptr) As Ptr
Declare Function NSClassFromString Lib "Foundation" (clsName As cfstringref) As Ptr
Declare Function stringWithString Lib "Foundation" Selector "stringWithString:" (clsRef As Ptr, Str As CFStringRef) As Ptr

'Declare Sub setValue Lib "UIKit" Selector "setValue:forPasteboardType:" (obj_id As Ptr, value As Ptr, pasteboardType As CFStringRef)

Dim pasteboard As ptr = generalPasteboard(NSClassFromString("UIPasteboard"))

Dim txt As Text = "Some text to place in the clipboard"

Declare sub setString lib "UIKit" selector "setString:" (obj_id as ptr, value as CFStringRef)
setString(pasteboard, txt)

Wow, thank you, Jeremie! :grinning: :+1:

1 Like