cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

objective-c API v2 - getMetaData Problem with Block response

objective-c API v2 - getMetaData Problem with Block response

ekantrowitz
New member | Level 2

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 2

mrschulz
Explorer | Level 3

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
Dropbox Staff
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.
Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    mrschulz Explorer | Level 3
What do Dropbox user levels mean?