OStack程序员社区-中国程序员成长平台

标题: ios - 我们如何在 iPhone sdk 中从 Evernote 导入图像 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 08:55
标题: ios - 我们如何在 iPhone sdk 中从 Evernote 导入图像

我正在开发一个绘图工具项目的应用程序,我们需要将印象笔记帐户中的图像导入我的应用程序。

我正在使用下面的代码来获取笔记列表。但我无法解码“data.bodyHash”NSData 并且图像变为 nil。您可以在下面的代码中看到。

EvernoteSession *session = [EvernoteSession sharedSession];
EDAMNoteFilter* filter = [[EDAMNoteFilter alloc] initWithOrder:0 ascending:NO words:nil notebookGuid:nil tagGuids:nil timeZone:nil inactive:NO emphasized:nil];
[[EvernoteNoteStore noteStore] findNotesWithFilter:filter offset:0 maxNotes:100 success:^(EDAMNoteList *list) {
    for (EDAMNote *note in list.notes) {
        NSLog(@"Notes : %@",note.title);
        NSMutableArray *resources = note.resources;
        if (resources!=nil) {
            EDAMResource* resource = [resources objectAtIndex:0];
            EDAMData *data = resource.data;
            UIImage *image = [[UIImage alloc]initWithData:data.bodyHash];
            /// Image is nil
        }
    }
}

谢谢



Best Answer-推荐答案


是的,这是可能的。您应该采取一些步骤来达到预期的效果。

1) 确保您的 Evernote 应用程序对用户的 Evernote 帐户具有完全访问权限,以便能够阅读现有笔记(您可以在 https://dev.evernote.com 上请求 Evernote API Key 时进行设置)

2) 认证

[self.session authenticateWithViewController:self
                          preferRegistration:NO
                                  completion:^(NSError* authenticateError) {
  ...
}];

3) 查找所有笔记

[self.session findNotesWithSearch:nil
                       inNotebook:nil
                          orScope:ENSessionSearchScopeAll
                        sortOrder:ENSessionSortOrderNormal
                       maxResults:255
                       completion:^(NSArray* findNotesResults,
                                    NSError* findNotesError) {
  ...
}];

4) 下载每条笔记

for (ENSessionFindNotesResult* result in findNotesResults) {
  [self.session downloadNote:result.noteRef
                    progress:NULL
                  completion:^(ENNote* note,
                               NSError* downloadNoteError) {
    ...
  }];
}

5) 获取所有图片

for (ENResource* resource in note.resources) {
  if ([resource.mimeType hasPrefix"image"]) {
    UIImage* image = [[UIImage alloc] initWithData:resource.data];
    ...
  }
}

您可以查看sample project here .
如果你设置了消费者 key 和 secret ,在认证之后你会看到类似的控制台输出:

2014-08-19 22:54:18.782 EvernoteTest[71234:60b] finding all notes..
2014-08-19 22:54:20.356 EvernoteTest[71234:60b] processing find notes results..
2014-08-19 22:54:21.294 EvernoteTest[71234:60b] getting images from note 'Just Image'
2014-08-19 22:54:21.294 EvernoteTest[71234:60b] >> image with size {600, 400}
2014-08-19 22:54:21.295 EvernoteTest[71234:60b] 
2014-08-19 22:54:21.720 EvernoteTest[71234:60b] getting images from note 'Getting Started'
2014-08-19 22:54:21.721 EvernoteTest[71234:60b] >> image with size {27, 27}
2014-08-19 22:54:21.721 EvernoteTest[71234:60b] >> image with size {215, 54}
2014-08-19 22:54:21.722 EvernoteTest[71234:60b] >> image with size {300, 300}
2014-08-19 22:54:21.722 EvernoteTest[71234:60b] >> image with size {27, 27}
2014-08-19 22:54:21.723 EvernoteTest[71234:60b] >> image with size {27, 27}
2014-08-19 22:54:21.723 EvernoteTest[71234:60b] >> image with size {27, 27}
2014-08-19 22:54:21.724 EvernoteTest[71234:60b] >> image with size {27, 27}
2014-08-19 22:54:21.724 EvernoteTest[71234:60b] >> image with size {27, 27}
2014-08-19 22:54:21.725 EvernoteTest[71234:60b] >> image with size {27, 27}
2014-08-19 22:54:21.725 EvernoteTest[71234:60b] 
2014-08-19 22:54:22.179 EvernoteTest[71234:60b] getting images from note 'Another Image'
2014-08-19 22:54:22.180 EvernoteTest[71234:60b] >> image with size {685, 514}
2014-08-19 22:54:22.180 EvernoteTest[71234:60b] 

希望对你有帮助

关于ios - 我们如何在 iPhone sdk 中从 Evernote 导入图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25363778/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4