Image 从粘贴板上剥离图像

Image 从粘贴板上剥离图像,image,uitextview,copy-paste,nsattributedstring,uipasteboard,Image,Uitextview,Copy Paste,Nsattributedstring,Uipasteboard,有人可以指导我如何从粘贴板上的属性文本中剥离图像吗 范例 我有一个UITextView,它支持NSAttribute字符串。如果我允许用户从粘贴板粘贴包含图像的内容(例如,从Safari应用程序中的网页复制的图片和文本),当我尝试保存时,它将使我的应用程序崩溃: *** Assertion failure in -[NSHTMLReader _addAttachmentForElement:URL:needsParagraph:usePlaceholder:], /SourceCache/UIF

有人可以指导我如何从粘贴板上的属性文本中剥离图像吗

范例

我有一个UITextView,它支持NSAttribute字符串。如果我允许用户从粘贴板粘贴包含图像的内容(例如,从Safari应用程序中的网页复制的图片和文本),当我尝试保存时,它将使我的应用程序崩溃:

*** Assertion failure in -[NSHTMLReader _addAttachmentForElement:URL:needsParagraph:usePlaceholder:], /SourceCache/UIFoundation_Sim/UIFoundation-78/UIFoundation/TextSystem/NSHTMLReader.m:1478
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unable to find missing_image.tiff!'
仅当图像是源副本的一部分时,才会发生这种情况。我不知道为什么它会提到tiff,因为我测试的源图像是jpg和png

如a中所述,我为避免崩溃而采取的解决方法是将粘贴板强制为常规字符串:

- (void)paste:(id)sender
{
    UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
    NSString *string = pasteBoard.string;
    [self insertText:string];
}
这确实可以防止崩溃,但也可以防止用户粘贴任何格式化文本。使用邮件应用程序中的粗体或斜体

所以我能说的最好的是,我需要从粘贴板上剥离任何图像,以便保留文本格式。谢谢你的帮助