October 11, 2012
Posted by William
iOS 6 UIPasteboard setImages and setImage
The iOS6 sdk has some changes to it. Along with these changes come changes to the UIPasteboard. One thing is the UIPasteboard now handles most images as NSData.
Here is my solution to accessing and setting images in the UIPasteBoard.
Accessing Images:
if ([obj isKindOfClass:[NSData class]]) {
UIImage* img = [[UIImage alloc] initWithData:(NSData*)obj];
} else if ([obj isKindOfClass:[UIImage class]]) {
UIImage* img = (UIImage*)obj;
}
}
I saw in a comment that setImages: is not functional, here is a fix:
Setting Images:
NSData* imageData = UIImageJPEGRepresentation(img, 1);
NSMutableDictionary *item = [NSMutableDictionary dictionary];
[item setValue:imageData forKey:(NSString*)kUTTypeJPEG];
[[UIPasteboard generalPasteboard] addItems:[NSArray arrayWithObject:item]];
}













