Skip to content

Instantly share code, notes, and snippets.

@Koze
Last active May 15, 2017 20:48
Show Gist options
  • Save Koze/ac37f2734560091c810c to your computer and use it in GitHub Desktop.
Save Koze/ac37f2734560091c810c to your computer and use it in GitHub Desktop.
Retrieve image data from NSTextAttachment
UIPasteboard *pboard = [UIPasteboard generalPasteboard];
NSData *data = [pboard valueForPasteboardType:@"com.apple.flat-rtfd"];
NSAttributedString *aString = [[NSAttributedString alloc] initWithData:data
options:@{NSDocumentTypeDocumentAttribute: NSRTFDTextDocumentType}
documentAttributes:nil
error:nil];
NSRange range = NSMakeRange(0, aString.length);
NSDictionary *attributes = [aString attributesAtIndex:0 effectiveRange:&range];
NSLog(@"%@", attributes);
NSTextAttachment *attachment = attributes[NSAttachmentAttributeName];
NSLog(@"%@", attachment);
NSLog(@"%@", attachment.image);
NSLog(@"%@", attachment.contents);
NSLog(@"%@", attachment.fileType);
NSLog(@"%@", attachment.fileWrapper);
NSFileWrapper *fileWrapper = attachment.fileWrapper;
NSLog(@"%@", fileWrapper.fileAttributes);
UIImage *image = [UIImage imageWithData:fileWrapper.regularFileContents];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment