Cut the Clutter: Test Ignore Files Feature - sign up to become a beta tester here.

Forum Discussion

ekantrowitz's avatar
ekantrowitz
New member | Level 2
9 years ago

objective-c API v2 - getMetaData Problem with Block response

I am converting to objective C API v2.  I wrote this route to verify if a file is in a dropbox directory called DA.  I get on the NSLog that the file exits, but the BOOL return value of the function is always 0.  Any help would be appreciated.

- (BOOL)verifyFileInDropboxWith:(NSString *)fileName {
    __block BOOL fileOnDB = NO;
    NSString *dBFilePath = [NSString stringWithFormat:@"/DA/%@",fileName];
    DropboxClient *client = [DropboxClientsManager authorizedClient];
    [[client.filesRoutes getMetadata:dBFilePath]
     response:^(DBFILESMetadata *result, DBFILESGetMetadataError *routeError, DBError *error){
         if([result.name containsString:fileName])
         {
             NSLog(@"File already exists DB");
             fileOnDB = YES;
         } else {
             NSLog(@"File does not exist in DB");
             fileOnDB = NO;
         }
     }];
    return (fileOnDB);
    
}

2 Replies

  • mrschulz's avatar
    mrschulz
    Explorer | Level 3
    8 years ago

    Your function does this

     

    set return value to NO

    call a block ( which takes some time, asynchronously )

    immediately return the return value

     

    The block will not set it to another value until it's done the dropbox API call.

     

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    8 years ago
    Mrschulz's comment is correct, the response block is asynchronous. The result of the API call is only returned in the response block, so you should trigger whatever is relying on that value inside the response block.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,037 PostsLatest Activity: 3 years ago
415 Following

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!