zolibra
zolibra

Reputation: 532

How can I decode the UIPasteboard type "apple web archive pasteboard" web content , and sync this with evernote api?

First , i try to get the webResourceData from UIPasteboard :

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"];

    }

}

then , i try to create a not with this data:

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

the problem is what I can see from Evernote is a attachment but not the web content...

Upvotes: 1

Views: 883

Answers (1)

Mustafa
Mustafa

Reputation: 5347

To show the web content you will need to embed it in the ENML, you don't need to add it to the Resources. Here is a simple example :

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

Upvotes: 1

Related Questions