iOS Question [Solved] Set/Get Text to Clipboard

aeric

Expert
Licensed User
Longtime User
I tried the following but it is not working.

B4X:
Sub SetTextToClipboard (Text As String)
    Dim Pasteboard As NativeObject
    Dim general As NativeObject = Pasteboard.Initialize("UIPasteboard").GetField("generalPasteboard")
    general.RunMethod("setString:", Array As Object(Text))
End Sub

Sub GetTextFromClipboard As String
    Dim Pasteboard As NativeObject
    Dim general As NativeObject = Pasteboard.Initialize("UIPasteboard").GetField("generalPasteboard")
    If general.IsInitialized Then
        Dim blnHasString As Boolean = general.GetField("hasStrings")
        If blnHasString Then
            Dim value As Object = general.RunMethod("string", Null)
            Return value
        End If
    End If
    Return ""
End Sub
 

Alexander Stolte

Expert
Licensed User
Longtime User
I didn't know it exists. :)
I found it using the B4I filter and "clipboard" as a search term in the 4th place in the following thread:

Many thanks! Have a nice day :)
 
Upvote 0
Top