Last active
May 15, 2017 20:48
-
-
Save Koze/ac37f2734560091c810c to your computer and use it in GitHub Desktop.
Retrieve image data from NSTextAttachment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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