Skip to content

Instantly share code, notes, and snippets.

@evernotegists
Created May 25, 2013 05:06
Show Gist options
  • Save evernotegists/5647970 to your computer and use it in GitHub Desktop.
Save evernotegists/5647970 to your computer and use it in GitHub Desktop.
Create complex note
- (void)makeNoteWithTitle:(NSString*)noteTile withBody:(NSString*) noteBody withResources:(NSMutableArray*)resources withParentBotebook:(EDAMNotebook*)parentNotebook {
NSString *noteContent = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">"
"<en-note>"
"%@",noteBody];
// Add resource objects to note body
if(resources.count > 0) {
noteContent = [noteContent stringByAppendingString:
@"<br />"];
}
// Include ENMLUtility.h .
for (EDAMResource* resource in resources) {
noteContent = [noteContent stringByAppendingFormat:@"Attachment : <br /> %@",
[ENMLUtility mediaTagWithDataHash:resource.data.bodyHash
mime:resource.mime]];
}
noteContent = [noteContent stringByAppendingString:@"</en-note"];
// Parent notebook is optional; if omitted, default notebook is used
NSString* parentNotebookGUID;
if(parentNotebook) {
parentNotebookGUID = parentNotebook.guid;
}
// Create note object
EDAMNote *ourNote = [[EDAMNote alloc] initWithGuid:nil title:noteTile content:noteContent contentHash:nil contentLength:noteContent.length created:0 updated:0 deleted:0 active:YES updateSequenceNum:0 notebookGuid:parentNotebookGUID tagGuids:nil resources:resources attributes:nil tagNames:nil];
// Attempt to create note in Evernote account
[[EvernoteNoteStore noteStore] createNote:ourNote success:^(EDAMNote *note) {
// Log the created note object
NSLog(@"Note created : %@",note);
} failure:^(NSError *error) {
// Something was wrong with the note data
// See EDAMErrorCode enumeration for error code explanation
// http://dev.evernote.com/documentation/reference/Errors.html#Enum_EDAMErrorCode
NSLog(@"Error : %@",error);
}];
}
@dsozdanoski
Copy link

Line 19 should be:

noteContent = [noteContent stringByAppendingString:@"</en-note>"];

an ">" is missing causing a malformed xml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment