Last active
December 17, 2015 02:59
-
-
Save maojj/5539672 to your computer and use it in GitHub Desktop.
get Image from pasteboard for ios
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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