Tutorials

iOS 6 UIPasteboard setImages and setImage

By |October 11th, 2012|

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:

for (NSObject* obj in [UIPasteboard generalPasteboard].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:

for (UIImage* img in myImagesArray) {
NSData* imageData = UIImageJPEGRepresentation(img, 1);
NSMutableDictionary *item = [NSMutableDictionary dictionary];
[item setValue:imageData forKey:(NSString*)kUTTypeJPEG];
[[UIPasteboard generalPasteboard] addItems:[NSArray arrayWithObject:item]];
}

Objective-C NSString Extracting Numbers

By |April 16th, 2011|

Parsing NSStrings for numbers