Unable to download the note attachmet using Everno

2019-09-03 14:41发布

问题:

I have integrated the latest evernote ios sdk from github, That support both regular user and also business user. I can able to list the note book and notes without any issues but when i try to download the note attachment its giving me the following error.

Error Domain=ENErrorDomain Code=1 "Missing result: getResourceData failed: unknown result" UserInfo=0x10dcb15f0 {NSLocalizedDescription=Missing result: getResourceData failed: unknown result} Skipping field: due to type mismatch (received:11)

Here the code i have used to download the note attachment.

+ (void)downloadDataWithNoteBook:(ENNotebook *)notebook fromNoteResource:(EDAMResource *)resource
onCompletion:(ZIdResultBlock)block {        
    ENPreferencesStore *preference = [ENSession sharedSession].preferences;     
    ENNoteStoreClient *noteStoreClient = [preference objectForKey:[SEEvernoteHelper getTitleForNoteAttachments:resource]];

    NSString *str = resource.guid; 
    NSLog(@"GUID = [%@]", resource.guid);
    [noteStoreClient getResourceDataWithGuid:resource.guid success:^(NSData *data) {        
             if(block) {            
                 block(data, nil);      
             }  
     }
     failure:^(NSError *error) {        
         if (block) {           
             block(nil, error);         
     }}];    
}

回答1:

Finally i was able to do it!!!

Here is my code:

//select the file that you want to download from evernote 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    isParentNoteBooks = false;
    if ([SEEvernoteHelper isNoteBookInstance:[self.datasourceObjects objectAtIndex:indexPath.row]]) {
        self.selectedNoteBook = [self.datasourceObjects objectAtIndex:indexPath.row];
        [self fetchAttachmentsForNoteBook:[self.datasourceObjects objectAtIndex:indexPath.row]];
        // set here if  the notebook is business or not.
        if ([SEEvernoteHelper isBussinessNoteBook:self.selectedNoteBook]) {
            isCurrentNoteBookBusiness = YES;
        }
        else{
            isCurrentNoteBookBusiness = NO;
        }
    } else {
        self.selectedFileNameToDownload = [SEEvernoteHelper getTitleForNoteAttachments:[self.datasourceObjects objectAtIndex:indexPath.row]];
        self.selectedResource = [self.datasourceObjects objectAtIndex:indexPath.row];
        [self downloadNoteResultObject:self.selectedResource];

    }
}

//start the download process
- (void)downloadNoteResultObject:(id)resultObject {
    MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    HUD.labelText = kStrDownloadingLabel;
    HUD.detailsLabelText = self.selectedFileNameToDownload;

    __weak __typeof__(self) weakSelf = self;
    [SEEvernoteHelper downloadDataWithNoteBook:self.selectedNoteBook fromNoteResource:resultObject onCompletion:^(id result, NSError *error) {
        if (result) {
            [NSThread syncOnMain:^{
                //save the downloaded data....
                [HUD hide:YES];
            }];
        } else {
            [HUD hide:YES];
            [NSThread syncOnMain:^{
                //error
            }];
        }
    }];
}

//get the download file
+ (void)downloadDataWithNoteBook:(ENNotebook *)notebook fromNoteResource:(EDAMResource *)resource onCompletion:(ZIdResultBlock)block {

    ENNoteStoreClient *noteStoreClient = [[ENSession sharedSession] noteStoreForNotebook:notebook];

    [noteStoreClient getResourceWithGuid:resource.guid withData:YES withRecognition:NO withAttributes:YES withAlternateDate:NO success:^(EDAMResource *resource) {
        if(block) {
            block(resource.data.body, nil);
        }

    } failure:^(NSError *error) {
        NSLog(@"Error : %@",error);
        if (block) {
            block(nil, error);
        }
    }];
}


标签: ios evernote