I currently have a UITextView that would represent an article in the app that I'm making. From the database, I am pulling a simple string that contains HTML formatting that I parse on-device. This is the function that parses the HTML for reference.
let htmlData = NSString(string: s).data(using: String.Encoding.unicode.rawValue);
let options = [NSAttributedString.DocumentReadingOptionKey.documentType:
NSAttributedString.DocumentType.html];
do{
let t = try NSMutableAttributedString(data: htmlData ?? Data(), options: options, documentAttributes: nil);
t.addAttribute(NSAttributedString.Key.font, value: UIFont(name: "SFProDisplay-Regular", size: CGFloat(fontSize)) as Any, range: NSMakeRange(0, t.length));
return t;
}
catch let error{
print(error);
return NSMutableAttributedString(string: s);
}
Anyways, in the article, this is the html code that is causing the issue:
Thanks! <span class="q9uorilb tbxw36s4 knj5qynh kvgmc6g5 ditlmg2l oygrvhab nvdbi5me fgm26odu gl3lb2sf hhz5lgdu"><img src="https://static.xx.fbcdn.net/images/emoji.php/v9/tfb/1/16/263a.png" alt="☺️" width="16" height="16" /></span></p>
On the app, it currently looks like this:
When long pressed, it opens up this menu on ios:

When pressing on the copy image button, it throws this error in xcode:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_UIConcretePasteboard setImage:]: Argument is not an object of type UIImage [(null)]'
I've looked online for a solution but it seems like there hasn't been anyone else with this issue. I've only seen solutions for people who have had issues pasting to the uitextview. I would think that converting the image into a UIImage would help fix this issue but I have no clue on where to start with an html image. Anything that will point me in the right direction will be greatly appreciated! Thanks.
