How to get Text from a Evernote note in iOS

75 views Asked by At

I am trying to download only image and text(probably HTML string) of a Evernote's note in my iOS app. I have successfully downloaded image from a note . But I did not find any method or process which help me to get text which are written on the note . I have used ENSDK.framework

-(void)findAllNotes {
     NSLog(@"finding all notes..");
    [self.session findNotesWithSearch:nil
                     inNotebook:nil
                     orScope:ENSessionSearchScopeAll
                     sortOrder:ENSessionSortOrderNormal
                     maxResults:255
                     completion:^(NSArray* findNotesResults,
                                  NSError* findNotesError) {

                                      if (findNotesError) {
                                           [self.session unauthenticate];
                                            NSAssert(NO, @"Could not find notes with error %@", findNotesError);
                                      } else {
                                             [self processFindNotesResults:findNotesResults];
                                        }
                     }];
}

- (void)processFindNotesResults:(NSArray*)results {
     NSParameterAssert(results);
     NSLog(@"processing find notes results..");

     for (ENSessionFindNotesResult* result in results) {
           [self.session downloadNote:result.noteRef
                  progress:NULL
                  completion:^(ENNote* note,
                  NSError* downloadNoteError) {
                  NSAssert(!downloadNoteError, @"Could not download note with error %@",
                                  downloadNoteError);

                 [self getDataFromNote:note];

                   }];
      }
}




-(void)getDataFromNote:(ENNote*)note {

    for (ENResource* resource in note.resources) {

        if ([resource.mimeType hasPrefix:@"image"]) {
        UIImage* image = [[UIImage alloc] initWithData:resource.data];
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);

            NSString *docs = [paths objectAtIndex:0];
            NSString* path =  [docs stringByAppendingFormat:@"/image1.jpg"];

            NSData* imageData = [NSData dataWithData:UIImageJPEGRepresentation(image, .8)];
            NSError *writeError = nil;

            if(![imageData writeToFile:path options:NSDataWritingAtomic error:&writeError]) {
                NSLog(@"%@: Error saving image: %@", [self class], [writeError localizedDescription]);
            }
        }

    }
}
1

There are 1 answers

0
Phil Seeman On

The content of the note is available to you in the content property of your variable note; i.e. it's in the content property of an ENNote object.

Also note that in addition to accessing the content directly, the Evernote iOS SDK also includes a special method that makes it easy to display a note's content in a UIWebView:

We've made this easy-- rather than serializing it to HTML and fussing with attached image resources, we've provided a method to generate a single Safari "web archive" from the note; this is a bundled data type which UIWebView natively knows how to load directly.