I currently have a UITextView that is displaying an NSAttributedString that contains HTML data with text and images. This data is received via API so images and text are all combined into one HTML string. This is the function that parses the HTML.
let htmlData = NSString(string: myString).data(using: String.Encoding.unicode.rawValue);
let options = [NSAttributedString.DocumentReadingOptionKey.documentType:
NSAttributedString.DocumentType.html];
do{
let text = try NSMutableAttributedString(data: htmlData ?? Data(), options: options, documentAttributes: nil);
text.addAttribute(NSAttributedString.Key.font, value: UIFont(name: "Arial", size: CGFloat(fontSize)) as Any, range: NSMakeRange(0, text.length));
return text;
}
catch let error{
print(error);
return NSMutableAttributedString(string: myString);
}
When long pressing on the image, a menu appears with two options (1. Copy image 2. Save to Camera Roll). When I click on Copy image, the app crashes with this error message:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_UIConcretePasteboard setImage:]: Argument is not an object of type UIImage [(null)]'
Does anyone know how to fix this so when long pressing on the image and selecting Copy image, it will not crash?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…