The main use of cardboard iPhone

I am trying to add plain text to iPhone Pasteboard. The following code does not work:

UIPasteboard *pboard = [UIPasteboard generalPasteboard]; NSString *value = @"test"; [pboard setValue: value forPasteboardType: @"public.plain-text"]; 

I assume the problem is with an argument of type PasteBoard. Passing @"public.plain-text" nothing happens. By kUTTypePlainText , the compiler complains about an incompatible pointer type, but not a failure, and nothing happens. Using kUTTypePlainText also seems to require binding to MobileCoreServices , which is not mentioned in the docs.

+6
ios copy-paste cocoa-touch uipasteboard
source share
3 answers

Responding to comments and my own question:

  • Setting the string pasteboard works.
  • Using setValue:forPasteboardType: also works if I use kUTTypeUTF8PlainText instead of kUTTypePlainText for a cardboard type.

I did not notice the string property because I went directly to the section "Getting and Configuring Individual Inventory Elements" .

The way I tested is to click on a text field and see if a popup appears.

I’m still not sure where the documents explain the UTT types for iPhone, including where to get them (Framework files, #include ), it seems that the document “Unified identifier of type identifiers” is still oriented to Mac OS. Since the constants gave me a warning about type mismatch, I thought I was doing something wrong, so I first tried using the NSString literal.

+8
source share

Use this header to get the value for kUTTypeUTF8PlainText;

 #import <MobileCoreServices/UTCoreTypes.h> 

You will need an affordable MobileCoreServices infrastructure.

+19
source share

Here are my experiments with inserting text on cardboard. I use the button to add text programmatically.

 #import <MobileCoreServices/MobileCoreServices.h> - (IBAction)setPasteboardText:(id)sender { UIPasteboard *pb = [UIPasteboard generalPasteboard]; NSString *text = @"東京京都大阪"; // Works, but generates an incompatible pointer warning [pb setValue:text forPasteboardType:kUTTypeText]; // Puts generic item (not text type), can't be pasted into a text field [pb setValue:text forPasteboardType:(NSString *)kUTTypeItem]; // Works, even with non-ASCII text // I would say this is the best way to do it with unknown text [pb setValue:text forPasteboardType:(NSString *)kUTTypeText]; // Works without warning // This would be my preferred method with UTF-8 text [pb setValue:text forPasteboardType:(NSString *)kUTTypeUTF8PlainText]; // Works without warning, even with Japanese characters [pb setValue:text forPasteboardType:@"public.plain-text"]; // Works without warning, even with Japanese characters [pb setValue:text forPasteboardType:@"public.text"]; // Check contents and content type of pasteboard NSLog(@"%@", [pb items]); } 

I inserted the contents into the text box for verification and changed the contents of the text each time to make sure that it wasn’t just reusing the previous paste.

+3
source share

All Articles