cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
Update: Find information on Dropbox support during COVID-19 here
Close
cancel
Showing results for 
Search instead for 
Did you mean: 

objective-c API v2 - getMetaData Problem with Block response

ekantrowitz New member | Level 2
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

Re: objective-c API v2 - getMetaData Problem with Block response

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.

 

Re: objective-c API v2 - getMetaData Problem with Block response

Dropboxer
Dropboxer
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.

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?