无法将html内容复制到UIPasteBoard

时间:2014-07-09 11:15:09

标签: html ios uipasteboard

我遇到将html内容复制到UIPasteBoard的问题。

我已检查过以下链接,但解决方案对我不起作用:

我已尝试过以下代码,但应用程序在此行崩溃:

[pasteboard setItems:[NSArray arrayWithObjects:htmlItem,nil]];

以下是我的代码:

 -(void)copyToClip
 {
   NSLog(@"%@",[UIPasteboard generalPasteboard].string);

   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]];

  }​

任何帮助将不胜感激。

0 个答案:

没有答案