2017-02-08 4 views
1

내 iOS 앱에 메모의 이미지와 텍스트 (주로 HTML 문자열) 만 다운로드하려고합니다. 메모에서 이미지를 성공적으로 다운로드했습니다. 그러나 나는 노트에 쓰여진 텍스트를 얻을 수있는 방법이나 과정을 찾지 못했습니다. 나는 ENSDK.frameworkiOS의 Evernote 메모에서 텍스트를 가져 오는 방법

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

    } 
} 

답변

0

메모의 내용은 note 당신의 변수의 content 속성에 당신 사용할 수 있습니다를 사용했다; 즉 ENNote 개체의 content 속성에 있습니다. 우리보다는이 easy--했습니다

:

또한 직접 콘텐츠에 액세스 외에도 에버 노트 아이폰 OS SDK는 또한 includes a special method이 쉽게 UIWebView에서 메모의 내용을 표시 할 수가 있습니다 이를 HTML로 직렬화하고 첨부 된 이미지 리소스로 격려해 주면서 노트에서 하나의 Safari "웹 아카이브"를 생성하는 방법을 제공했습니다. 이것은 UIWebView가 기본적으로 직접로드하는 방법을 알고있는 묶음 데이터 유형입니다.

+0

Thnks. 하지만 코드 레벨 도움말을 원합니다. –