Copy images to pasteboard as data, not UIImage.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-03-25 11:26:16 -04:00
parent 7a7cc34cdd
commit 86abb43c30

View file

@ -7,6 +7,7 @@
#import "JSQMediaItem+OWS.h"
#import "TSAttachmentStream.h"
#import <JSQMessagesViewController/JSQMessagesMediaViewBubbleImageMasker.h>
#import <MobileCoreServices/MobileCoreServices.h>
@interface TSPhotoAdapter ()
@ -112,7 +113,18 @@
}
if (action == @selector(copy:)) {
UIPasteboard.generalPasteboard.image = self.image;
OWSAssert(self.attachment.filePath.length > 0);
NSString *fileExtension = [self.attachment.filePath pathExtension];
NSArray *utiTypes = (__bridge_transfer NSArray *)UTTypeCreateAllIdentifiersForTag(
kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExtension, (CFStringRef) @"public.image");
NSString *utiType = (NSString *)kUTTypeImage;
OWSAssert(utiTypes.count > 0);
if (utiTypes.count > 0) {
utiType = utiTypes[0];
}
NSData *data = [NSData dataWithContentsOfURL:self.attachment.mediaURL];
[UIPasteboard.generalPasteboard setData:data forPasteboardType:utiType];
return;
} else if (action == NSSelectorFromString(@"save:")) {
UIImageWriteToSavedPhotosAlbum(self.image, nil, nil, nil);