解决方法
以下代码将从您的应用程序和Apple的Mail应用程序中获取HTML.该文档并没有为您提供大量帮助,因此部分原因在于查看Apple的应用程序驻留在粘贴板上然后进行逆向工程.该解决方案利用早期的
stackoverflow post – 跟进那里的链接以获得更多背景.
NSLog(@"Place HTML on the pasteboard"); UIPasteboard* pasteboard = [UIPasteboard generalPasteboard]; NSString *htmlType = @"Apple Web Archive pasteboard type"; // example html string NSString* htmlString = @"<p style=\"color:gray\"> <a href=@\"http://itunes.apple.com/gb/app/paragraft/id412998778?mt=8\">Paragraft</a><br><em>Less than a word processor,more than plain text</em>"; NSMutableDictionary *resourceDictionary = [NSMutableDictionary dictionary]; [resourceDictionary setObject:[htmlString dataUsingEncoding:NSUTF8StringEncoding] forKey:@"WebResourceData"]; [resourceDictionary setObject:@"" forKey:@"WebResourceFrameName"]; [resourceDictionary setObject:@"text/html" forKey:@"WebResourceMIMEType"]; [resourceDictionary setObject:@"UTF-8" forKey:@"WebResourceTextEncodingName"]; [resourceDictionary setObject:@"about:blank" forKey:@"WebResourceURL"]; NSDictionary *containerDictionary = [NSDictionary dictionaryWithObjectsAndKeys:resourceDictionary,@"WebMainResource",nil]; NSDictionary *htmlItem = [NSDictionary dictionaryWithObjectsAndKeys:containerDictionary,htmlType,nil]; [pasteboard setItems: [NSArray arrayWithObjects: htmlItem,nil]]; // This approach draws on the blog post and comments at: // http://mcmurrym.wordpress.com/2010/08/13/pasting-simplehtml-into-the-mail-app-ios/