1

I am having problem to copy html content to UIPasteBoard.

I have checked below links but the solution does not work for me :

I have tried below code but application is crashing at this line :

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

Below is my code :

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

  }​

Any help will be appreciated.

Community
  • 1
  • 1
Siddharth_Vyas
  • 9,972
  • 10
  • 39
  • 69

0 Answers0