Clipboard

That is it. A+++. Great job. Thanks for your help.

[quote=159098:@Jason King]Public.text needs to be quoted because it is a string. So it should be:

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 setValue(generalPasteboard(NSClassFromString("UIPasteboard")), stringWithString(NSClassFromString("NSString"),"Hello world"), "public.text")[/quote]

Superb. Thank you Jason. I still have a lot to learn, but your example will help :slight_smile:

Any ideas on how to read a Text object from Pasteboard. I tried this:

declare function generalPasteboard lib “UIKIt” selector “generalPasteboard” (clsRef as ptr) as ptr
declare function NSClassFromString lib “Foundation” (clsName as cfstringref) as ptr
declare function getValue lib “UIKit” selector “value:forPasteboardType:” (obj_id as ptr, pasteboardType as CFStringRef) as CFStringRef

dim strRef as CFStringRef
strRef = getValue(generalPasteboard(NSClassFromString(“UIPasteboard”)), “public.text”)

It crashed on the getValue call. I also tried this, but that also crashed.

dim theText as Text
theText = getValue(generalPasteboard(NSClassFromString(“UIPasteboard”)), “public.text”)

You getValue declare is wrong. Change it to “valueForPasteboardType:”. There is only one argument passed to the function so you only need a single “:” at the end.

If use this in my iOS apps.

// Copy to Clipboard
declare sub setValue lib “UIKit” selector “setValue:forPasteboardType:” (obj_id as ptr, value as ptr, pasteboardType as CFStringRef)
Dim MyClip as Text
MyClip = CurrentEntry.PostalCode + " " + CurrentEntry.PlaceName
// Copy ZIP and City to Clipboard
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
setValue(generalPasteboard(NSClassFromString(“UIPasteboard”)), stringWithString(NSClassFromString(“NSString”),MyClip), “public.text”)

This works no longer in iOS 11.x on a real device (iPhone, iPad). It works in the simulator with iOS 10.3.x and not on a device with iOS 11.