William Sidell

Software Developer Entrepreneur

  • HomeAll the news
  • Portfoliovery cool stuff
  • AboutA bit about me
  • ConnectFind me on the grid

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:

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]];
}

1 Comment

Posted Under iOS Tutorials

1 Comments

rob
December 20, 2012

OMG you are awesome!

I have been struggling with this all day!

Thank you thank you thank you !

Leave a comment

* = Required

    • Posts
    • Twitter
    • Flickr
     

    iOS 6 UIPasteboard...

    iOS

     

    Three20 iOS 6...

    iOS

     

    1st Place Startup...

    iOS

    Check out this awesome Photo Mosaic I made using "InstaMosaic" for iPhone http://t.co/b4cYtyDu http://t.co/I9uc7clq

    follow me on
    twitter

    113DSC_7657.jpg_MG_0455.jpgFlower-3
  • Categories

    • Interesting Stuff
    • iOS
    • Tutorials
  • Archives

    • 2012
      • January
      • March
      • September
      • October
    • 2011
      • February
      • March
      • April
      • June
    • 2010
      • October
  • Blogroll

    • Enchanted Cloud Studios

Subscribe via RSS