Skip to content

Instantly share code, notes, and snippets.

@maojj
Last active December 17, 2015 02:59
Show Gist options
  • Save maojj/5539672 to your computer and use it in GitHub Desktop.
Save maojj/5539672 to your computer and use it in GitHub Desktop.
get Image from pasteboard for ios
#define WEB_ARCHIVE @"Apple Web Archive pasteboard type"
- (void)getImage {
if ([[[UIPasteboard generalPasteboard] pasteboardTypes] containsObject:WEB_ARCHIVE]) {
NSData* archiveData = [[UIPasteboard generalPasteboard] valueForPasteboardType:WEB_ARCHIVE];
if (archiveData)
{
NSError* error = nil;
id webArchive = [NSPropertyListSerialization propertyListWithData:archiveData options:NSPropertyListImmutable format:NULL error:&error];
if (error) {
return;
}
NSArray *subItems = [NSArray arrayWithArray:[webArchive objectForKey:@"WebSubresources"]];
NSPredicate *iPredicate = [NSPredicate predicateWithFormat:@"WebResourceMIMEType like 'image*'"];
NSArray *imagesArray = [subItems filteredArrayUsingPredicate:iPredicate];
for (int i=0; i<[imagesArray count]; i++) {
NSDictionary *sItem = [NSDictionary dictionaryWithDictionary:[imagesArray objectAtIndex:i]];
UIImage *sImage = [UIImage imageWithData:[sItem valueForKey:@"WebResourceData"]];
NSString *sImageSrc = [sItem valueForKey:@"WebResourceURL"];
NSString *sMIMEType = [sItem valueForKey:@"WebResourceMIMEType"];
// handle images
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment