copy HTML to UIPasteboard

后端 未结 4 1766
别跟我提以往
别跟我提以往 2021-01-03 09:07

I want to transfer HTML from my app to the iPhone mail application. I already have the HTML text - lest say <span style=\'color:red\'>Test</span> I can place this to U

相关标签:
4条回答
  • 2021-01-03 09:15

    No, it cannot. UIPasterBoard only accepts strings, images, URLs and colors.

    0 讨论(0)
  • 2021-01-03 09:26

    on that same link you gave in your comment, you'll find this paragraph at the top.

    A Uniform Type Identifier (UTI) is frequently used for a representation type (sometimes called a pasteboard type). For example, you could use kUTTypeJPEG (a constant for public.jpeg) as a representation type for JPEG data. However, applications are free to use any string they want for a representation type; however, for application-specific data types, it is recommended that you use reverse-DNS notation to ensure the uniqueness of the type (for example, com.myCompany.myApp.myType).

    Right below it is a link to here. http://developer.apple.com/iphone/library/documentation/FileManagement/Conceptual/understanding_utis/understand_utis_intro/understand_utis_intro.html#//apple_ref/doc/uid/TP40001319

    Which explains UTIs.

    Finally this link gives you SEVERAL types http://developer.apple.com/iphone/library/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html#//apple_ref/doc/uid/TP40009259-SW1

    Of course that list isn't ALL types as you can create your own types.

    I have successfully pasted html into the mail app. I'll give you a good place to start...

    Create an app that will show the data types in the pasteboard. Goto safari on the device, copy a web page. Run your app, You'll notice the pasteboard type is "Apple Web Archive pasteboard type." Note that this is really a pasteboard type (a custom one). If you try to duplicate the safari mobile copy and paste feature yourself by creating a web archive and attempt to paste it as text into the mail app, it will show the web archive file as raw xml. If you define the type as "Apple Web Archive pasteboard type" the mail app will actually format the paste as html.

    If you want to know what a web archive looks like. On desktop safari, just save a web page as an archive and look at the file in a text reader (text edit will try to parse it, so you might use a different program to look at the archive xml).

    Please read all of the documentation as you can discover that you can do custom types in the link that you sent me.

    0 讨论(0)
  • 2021-01-03 09:29

    That is not true. you can paste ANYTHING to the pasteboard, go read the docs.

    I've finally put together a tutorial that shows how to copy HTML into the Mail app. http://mcmurrym.wordpress.com/2010/08/13/pasting-simplehtml-into-the-mail-app-ios/

    0 讨论(0)
  • 2021-01-03 09:30

    I've got HTML copy working so it pastes into the built-in Mail and Notes apps properly. It looks like this:

    NSString *htmlContent = @"This is <span style='font-weight:bold'>HTML</span>";
    NSString *content = @"This is HTML!";
    NSDictionary *dict = @{(NSString *)kUTTypeText: content, (NSString *)kUTTypeHTML: htmlContent};
    [[UIPasteboard generalPasteboard] setItems:@[dict]];
    

    To get access to those type constants, you need to import this:

    #import <MobileCoreServices/UTCoreTypes.h>
    
    0 讨论(0)
提交回复
热议问题