NSAttributedString from HTML in the background thread

后端 未结 2 1556
臣服心动
臣服心动 2020-12-19 06:58

What I need is to create NSAttributedString objects from relatively big HTML strings and store them (NSAttributedString-s) in the database. And of course I woul

相关标签:
2条回答
  • 2020-12-19 07:37

    You can try NSAttributedString+DDHTML. AFAIK it doesn't depend on WebKit and I used it successfully for simple HTMLs. I haven't tried using it in the background thread, but I suppose it shouldn't be a problem.

    And watch out - it may crash when HTML includes font which is unavailable on iOS. I've issued a pull request for that.

    0 讨论(0)
  • 2020-12-19 07:57

    Yes you can't it in a background thread only on main thread. Use Oliver Drobnik's NSAttributedString+HTML class.

    Code would be something like this -

    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithHTML:<html> dataUsingEncoding:NSUTF8StringEncoding] documentAttributes:nil];
    

    Link - https://github.com/InfiniteLoopDK/NSAttributedString-Additions-for-HTML/blob/master/Classes/NSAttributedString%2BHTML.m

    0 讨论(0)
提交回复
热议问题