Reputation: 20376
I am copying a webpage and would like to see how the dictionary copied to the UIPasteBoard is composed. I currently log the item on the general pasteboard as follows:
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
for (NSDictionary *dict in pasteboard.items) {
NSLog(@"Dict: %@", dict);
}
The output is:
Dict: {
"Apple Web Archive pasteboard type" = <62706c69 73743030 d2010203 0d5f100f 57656253 75627265 736f7572 6365735f 100f5765 624d6169 6e526573 6f757263 65a104d4 05060708 090a0b0c 5e576562 5265736f 75726365 55524c5f 100f5765.............
I have tried getting a string for the "Apple Web Archive pasteboard type" key as follows, but with no success:
NSString *string = [[NSString alloc] initWithData:[dict objectForKey:@""Apple Web Archive pasteboard type""] encoding:NSUTF8StringEncoding];
NSLog(@"item %@", string);
How can I decode the data for this key please?
Upvotes: 3
Views: 2658
Reputation: 648
For reference, a 3rd party standalone library to access WebArchives on iOS exists: http://www.cocoanetics.com/2011/09/decoding-safaris-pasteboard-format/ https://github.com/Cocoanetics/DTWebArchive
Upvotes: 1
Reputation: 51
Apple Web Archive pasteboard type is Plist, for discover keys - open with Plist editor. Also short piece of code below (getting images info from pasted web page)
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"]];
// handle images
}
}
}
Upvotes: 5
Reputation: 18477
Check out the WebKit documentation here: WebArchive Class Reference
Keep in mind that this is a 'private' class on iOS. Sending messages to this object or otherwise interacting with it may be grounds for your app being rejected in review.
Upvotes: 0
Reputation: 55563
You could try this:
NSData *data = (NSData *) [dict objectForKey:[[dict allKeys] objectAtIndex:0]];
Upvotes: -1