Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For those of you playing along at home, here's the answer we discovered.</p> <p>"public.utf8-plain-text" has historically been the correct UTI to use when putting an NSString containing unformatted text into the pasteboard. The built-in controls all request and use this version of the pasteboard contents during their "paste" operations (for iOS versions prior to 5). If you put only "public.plain-text" or "public.text" text in the pasteboard, the built-in controls ignore it completely, saying the pasteboard is empty (not giving you the "paste" option).</p> <p>In iOS 5, something changed and when the built-in controls request plain text in the situation above, they will get the "public.html" text.</p> <p>For iOS 5 you must use "public.text" instead of "public.plain-text" or "public.utf8-plain-text" even though the latter two are arguably more correct and the former is too vague to be of use at all.</p> <p>Since earlier iOS versions ignore "public.text", our solution is to put all three versions on the pasteboard: "public.text" and "public.utf8-plain-text" will both get you the plain text and "public.html" will get you the HTML text. This seems to satisfy both iOS 4 and 5 without having to put an explicit iOS version test in the code, at the cost of one more entry in the dictionary.</p> <p>One more fail for the kids at Apple.</p> <p><strong>EDIT for 2016 and iOS 8/9</strong></p> <p>I've been trying to solve this problem once and for all ever since I posted this question. Whenever I do a Google search, I always end up back at this question.</p> <p>Somewhere along the line, iOS introduced a "web archive" concept for putting HTML on the pasteboard. It's not documented well anywhere. I found an answer <a href="https://mcmurrym.wordpress.com/2010/08/13/pasting-simplehtml-into-the-mail-app-ios/" rel="nofollow">here</a> which pre-dates my question, so that's a little frustrating, but it works. I've updated it to take advantage of built-in base64 encoding in later versions of iOS. It goes something like this:</p> <pre><code>NSMutableDictionary * contents = [NSMutableDictionary dictionaryWithCapacity:6]; NSString * htmlText = @"&lt;h1&gt;A Heading&lt;/h1&gt;&lt;p&gt;A paragraph.&lt;/p&gt;" //... put other formats in the dictionary, then... NSData * data = [htmlText dataUsingEncoding:NSUTF8StringEncoding]; NSString * base64encodedString = [data base64EncodedStringWithOptions:0]; NSString * webArchiveString = [NSString stringWithFormat: @"&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;" "&lt;!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"&gt;" "&lt;plist version=\"1.0\"&gt;" "&lt;dict&gt;" "&lt;key&gt;WebMainResource&lt;/key&gt;" "&lt;dict&gt;" "&lt;key&gt;WebResourceData&lt;/key&gt;" "&lt;data&gt;%@&lt;/data&gt;" "&lt;key&gt;WebResourceFrameName&lt;/key&gt;" "&lt;string&gt;&lt;/string&gt;" "&lt;key&gt;WebResourceMIMEType&lt;/key&gt;" "&lt;string&gt;text/html&lt;/string&gt;" "&lt;key&gt;WebResourceTextEncodingName&lt;/key&gt;" "&lt;string&gt;UTF-8&lt;/string&gt;" "&lt;key&gt;WebResourceURL&lt;/key&gt;" "&lt;string&gt;about:blank&lt;/string&gt;" "&lt;/dict&gt;" "&lt;/dict&gt;" "&lt;/plist&gt;", base64encodedString]; [contents setObject:webArchiveString forKey:@"Apple Web Archive pasteboard type"]; UIPasteboard * pasteboard = [UIPasteboard generalPasteboard]; pasteboard.items = [NSArray arrayWithObject:contents]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload