我正在复制一个网页,想看看复制到UIPasteBoard的字典是如何组成的。我目前在通用粘贴板上记录该项目,如下所示:
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
for (NSDictionary *dict in pasteboard.items) {
NSLog(@"Dict: %@", dict);
}输出为:
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.............我尝试获取"Apple Web Archive pasteboard type“键的字符串,如下所示,但没有成功:
NSString *string = [[NSString alloc] initWithData:[dict objectForKey:@""Apple Web Archive pasteboard type""] encoding:NSUTF8StringEncoding];
NSLog(@"item %@", string);请问如何对这个密钥的数据进行解码?
发布于 2013-01-31 16:23:25
Apple Web Archive粘贴板类型为Plist,用于发现密钥-使用Plist编辑器打开。下面还有一小段代码(从粘贴的网页中获取图片信息)
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
}
}
}发布于 2015-01-29 12:19:50
作为参考,存在用于访问iOS上的WebArchives的第三方独立库:http://www.cocoanetics.com/2011/09/decoding-safaris-pasteboard-format/ https://github.com/Cocoanetics/DTWebArchive
发布于 2012-02-07 01:49:39
请在此处查看WebKit文档:WebArchive Class Reference
请记住,这是iOS上的一个“私有”类。向此对象发送消息或以其他方式与其交互可能会导致您的应用程序在审核中被拒绝。
https://stackoverflow.com/questions/9164509
复制相似问题