gpt4 book ai didi

iphone - 解码 UIPasteboard 上的 "Apple Web Archive pasteboard type"项目

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:51:26 27 4
gpt4 key购买 nike

我正在复制网页,想看看复制到 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.............

我尝试如下获取“Ap​​ple Web Archive 粘贴板类型”键的字符串,但没有成功:

NSString *string = [[NSString alloc] initWithData:[dict objectForKey:@""Apple Web Archive pasteboard type""] encoding:NSUTF8StringEncoding];

NSLog(@"item %@", string);

请问我如何解码此 key 的数据?

最佳答案

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

}

关于iphone - 解码 UIPasteboard 上的 "Apple Web Archive pasteboard type"项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9164509/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com