Skip to content

Commit

Permalink
specify UTType with data
Browse files Browse the repository at this point in the history
  • Loading branch information
joewalsh committed May 29, 2018
1 parent 97d56b7 commit 88d2a1a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions Example/NYTExamplePhoto.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// Redeclare all the properties as readwrite for sample/testing purposes.
@property (nonatomic) UIImage *image;
@property (nonatomic) NSData *imageData;
@property (nonatomic) NSString *imageDataUTType;
@property (nonatomic) UIImage *placeholderImage;
@property (nonatomic) NSAttributedString *attributedCaptionTitle;
@property (nonatomic) NSAttributedString *attributedCaptionSummary;
Expand Down
8 changes: 5 additions & 3 deletions NYTPhotoViewer/NYTPhotosViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ - (void)dealloc {

- (void)copy:(id)sender {
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
if (self.currentlyDisplayedPhoto.imageData) {
[pasteboard setData:self.currentlyDisplayedPhoto.imageData forPasteboardType:(NSString *)kUTTypeImage];
NSData *data = self.currentlyDisplayedPhoto.imageData;
NSString *type = self.currentlyDisplayedPhoto.imageDataUTType;
if (data && type) {
[pasteboard setData:data forPasteboardType:type];
} else {
[pasteboard setImage:self.currentlyDisplayedPhoto.image];
}
Expand All @@ -85,7 +87,7 @@ - (BOOL)canBecomeFirstResponder {
}

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
BOOL containsImage = self.currentlyDisplayedPhoto.image || self.currentlyDisplayedPhoto.imageData;
BOOL containsImage = self.currentlyDisplayedPhoto.image || (self.currentlyDisplayedPhoto.imageData && self.currentlyDisplayedPhoto.imageDataUTType);

if (self.shouldHandleLongPress && action == @selector(copy:) && containsImage) {
return YES;
Expand Down
5 changes: 5 additions & 0 deletions NYTPhotoViewer/Protocols/NYTPhoto.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, readonly, nullable) NSData *imageData;

/**
* The UTType of the image data
*/
@property (nonatomic, readonly, nullable) NSString *imageDataUTType;

/**
* A placeholder image for display while the image is loading.
*
Expand Down

0 comments on commit 88d2a1a

Please sign in to comment.