首先,我尝试从 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 看到的是附件,而不是网页内容......