2

I am using below code to convert HTML text into NSMutableAttributedString and showing it in UITextView. -

attributedStringTitle = [[NSMutableAttributedString alloc] initWithData:[titleString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];

This is working fine for iOS 7 or later but not working on iOS 6.. Please help.

Jogendra.Com
  • 6,394
  • 2
  • 28
  • 35
Viper
  • 1,408
  • 9
  • 13

3 Answers3

1

NSHTMLTextDocumentType is not available in iOS6:

From the Apple docs:

NSHTMLTextDocumentType Hypertext Markup Language (HTML) document.

Available in iOS 7.0 and later.

zaph
  • 111,848
  • 21
  • 189
  • 228
1

That is because NSHTMLTextDocumentType is only available on iOS 7 and later. Read here for the list of available constants.

Levi
  • 7,313
  • 2
  • 32
  • 44
  • Look for a 3rd party framework, or handle manually the components from the HTML doc – Levi Oct 28 '14 at 11:53
1

As per Docs NSHTMLTextDocumentType is only available on iOS 7 and later So there are some alternatives which you can do:-

1)For this you can use a 3rd party Framework.

2)Use UIWebView

3)Refer this display-html-text-in-uitextview

But if you only need to parse html tags into strings then you can use initWithString api for your workaround. But before that you need to create the string object str from NSData using initWithData:-

- (NSString *)initWithData:(NSData *)data encoding:(NSStringEncoding)encoding;
- (id)initWithString:(NSString *)str attributes:(NSDictionary *)attrs;

Note:- The above two api will parse html tags as a plain text

Community
  • 1
  • 1
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56