Basic iPhone pasteboard usage

Luís Marques picture Luís Marques · Jun 28, 2009 · Viewed 11.1k times · Source

I'm trying to put some plain text in the iPhone Pasteboard. The following code doesn't seem to work:

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

I'm guessing the problem is in the PasteBoard type argument. Passing @"public.plain-text" nothing happens. Passing kUTTypePlainText the compiler complains about incompatible pointer type, but doesn't crash, and nothing happens either. Using kUTTypePlainText also seems to require linking with MobileCoreServices, which is not mentioned in the docs.

Answer

kickingvegas picture kickingvegas · Jul 14, 2009

Use this header to get the value for kUTTypeUTF8PlainText;

#import <MobileCoreServices/UTCoreTypes.h>

You'll need to have the MobileCoreServices framework available.