如何在iOS上使用evernote api处理多线程

时间:2012-03-31 17:20:17

标签: ios multithreading evernote

我现在正在使用evernote api在iOS上开发应用程序。我有一些关于多线程的问题。以下是我的应用程序中的多线程机制,是好还是坏?任何建议都是受欢迎的。

  1. 使用MainThread(线程a)显示和刷新UI。
  2. 当用户在noteList页面时,使用线程b从evernote下载noteList。
  3. 当用户在noteDetail页面时,使用Thread c从evernote下载noteResource。
  4. 如果用户在线程b未完成时单击noteList页面中的一个注释。我应该在使用线程c下载noteResource之前取消线程b吗?或者一次运行Thread b和Thread c是否安全?

    有关这方面的任何文件或学费吗?

    我在下面添加了代码,是吗?当用户首次登录时,masterSync将运行,note标题将下载并显示。在此之后,如果用户按下同步按钮,masterSync将再次运行,但现在当在noteStore alloc / init时访问authenticationToken的authResult时崩溃,我在用户登录成功时保存了authResult,是对吗?

    -(void)sync:(id)obj {
        NSOperationQueue *operationQueue = [AppDelegate sharedOperationQueue];
    
        if ([obj isKindOfClass:[Note class]]) {
            self.detailSync = [[[EvernoteDetailSync alloc] initWithNote:obj] autorelease];
            detailSync.noteStore =[[[EvernoteNoteStore alloc] initWithToken:[authResult authenticationToken] shardId:[[authResult user] shardId]] autorelease];
            [operationQueue addOperation:detailSync];
        } else {
            self.masterSync = [[[EvernoteMasterSync alloc] initWithNotebookGuid:obj] autorelease];
            masterSync.noteStore =[[[EvernoteNoteStore alloc] initWithToken:[authResult authenticationToken] shardId:[[authResult user] shardId]] autorelease];
            [operationQueue addOperation:masterSync];
        }
    }
    

1 个答案:

答案 0 :(得分:0)

Evernote NoteStore类不是线程安全的。要创建多个并发Evernote API请求,您可以创建多个NoteStore对象。