如何解码UIPasteboard类型的“apple web archive pasteboard”Web内容,并将其与evernote api同步?

时间:2013-06-19 23:10:31

标签: ios evernote uipasteboard webarchive

首先,我尝试从UIPasteboard获取webResourceData:

if ([[pasteboard pasteboardTypes] containsObject:@"Apple Web Archive pasteboard type"]) {
    NSData* archiveData = [[UIPasteboard generalPasteboard] valueForPasteboardType:@"Apple Web Archive pasteboard type"];
    if (archiveData)
    {
        if (DEBUG) [self checkPasteboard];
        NSError* error = nil;
        id webArchive = [NSPropertyListSerialization propertyListWithData:(NSData *)archiveData options:NSPropertyListImmutable format:NULL error:&error];
        if (error) {
            //TODO:
            DLog(@"format error!");
        }
        NSDictionary* webMainResource = [webArchive objectForKey:@"WebMainResource"];
        NSData * webResourceData = [dic objectForKey:@"WebResourceData"];

    }

}

然后,我尝试用这个数据创建一个not:

NSData *dataHash = [webResourceData enmd5];
EDAMData *edamData = [[EDAMData alloc] initWithBodyHash:dataHash size:webResourceData.length body:webResourceData];
EDAMResource* resource = [[EDAMResource alloc] initWithGuid:nil noteGuid:nil data:edamData mime:@"text/html" width:0 height:0 duration:0 active:0 recognition:0 attributes:nil updateSequenceNum:0 alternateData:nil];
NSString *noteContent = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                         "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">"
                         "<en-note>"
                         "<span style=\"font-weight:bold;\">Hello Evernote.</span>"
                         "</en-note>"];
NSMutableArray* resources = [NSMutableArray arrayWithArray:@[resource]];
EDAMNote *newNote = [[EDAMNote alloc] initWithGuid:nil title:@"Test note" content:noteContent contentHash:nil contentLength:noteContent.length created:0 updated:0 deleted:0 active:YES updateSequenceNum:0 notebookGuid:nil tagGuids:nil resources:resources attributes:nil tagNames:nil];
[[EvernoteNoteStore noteStore] setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
    DLog(@"Total bytes written : %lld , Total bytes expected to be written : %lld",totalBytesWritten,totalBytesExpectedToWrite);
}];
[[EvernoteNoteStore noteStore] createNote:newNote success:^(EDAMNote *note) {
    DLog(@"Note created successfully.");
    //TODO: need delete the cell

} failure:^(NSError *error) {
    DLog(@"Error creating note : %@",error);
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                    message:[error.userInfo objectForKey:@"NSLocalizedDescription"]
                                                   delegate:nil
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];
    [alert show];
}];

问题是我从Evernote看到的是附件而不是网络内容......

1 个答案:

答案 0 :(得分:1)

要显示您需要将其嵌入ENML的网络内容,您无需将其添加到资源中。这是一个简单的例子:

<?xml version='1.0' encoding='utf-8'?> 
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"> 
<en-note>  
    <h1>   
    Simple HTML note  
    </h1> 
</en-note>