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: 
Highlighted

DBRpcTask response block not called.

Explorer | Level 3

I have a method that calls [client.filesRoutes createFolder:folderPath]. In its response block a call is made to [client.filesRoutes search:parentPath query:filename]. In its response block another call is made to [client.filesRoutes createFolder:folderPath] (checking for another folder) and so forth recuresively until everything gets unwound.  The first call works (response block is called) but the second (recursive) call does not result in its response bock being called. For example, the  [client.filesRoutes createFolder:folderPath] call created the folder but the response block is never called.  I am updating previously written code that worked fine when DBRestClient callbacks were used.  Not sure if this has something to do with calling Dropbox methods from within a response block that has a response block itself. 

 

Thank you.

4 Replies 4
Highlighted

Re: DBRpcTask response block not called.

Dropboxer
Dropboxer
Can you share the code that reproduces this, so we can make sure we understand the issue? Thanks in advance!
Highlighted

Re: DBRpcTask response block not called.

Explorer | Level 3

Here is the code.  I tried to make it as minimal as possible but I think the pattern is clear.

 

 

- (DocumentMetaData createFolder:(DocumentMetaDatafolderInfo {
    NSURL *folderURL = [folderInfo itemURL];
    NSString *folderPath = [[folderURL path] stringByReplacingPercentEscapesUsingEncoding:UTF8Encoding];
    DBUserClient *client = [self getDropboxClient];
 
    [[client.filesRoutes createFolder:folderPath] setResponseBlock:^(DBFILESFolderMetadata *result, DBFILESCreateFolderError *routeError, DBRequestError *networkError) {
         if (result) {
             if ([delegate respondsToSelector:@selector(checkFolderCreated)]) {
                 [delegate checkFolderCreated:YES];
             }
         } else {
             LALog(@"%@\n%@\n", routeError, networkError);
}
}];
 
    //Wait-loop for create folder request with the given timeout
    NSDate* giveUpDate = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_CREATE_FOLDER_IN_SECS];
    while ( (self.currentRequestStatus == REQ_PROCESSING) &&
           [giveUpDate timeIntervalSinceNow] > 0) {
        //Keep looping.. Run the current run for a millisec for the Network and UI async events to be taken care of
        NSDate *stopDate = [NSDate dateWithTimeIntervalSinceNow:0.001];
        [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:stopDate];
    }
 
Delegate Class:
 
- (void) checkFolderCreated:(BOOL)success withInfo:(NSDictionary infoPassedIn {
DocumentController *docController = (DocumentController[infoPassedIn objectForKey:@"DocumentController"];
     if (docController == nil)
        return;
 
…
 
[docController createFolder:docMetaData];
 
…
 
// some condition to pop out.
}

 

Here the first call to createFolder successfully has its response block called.  All additional calls execute the createFolder method (the folder is created) but the response block is not called.

 

The while loop is used to make the call synchronous in this case.  This may be interfering with the response block being called back but not sure.  Any ideas?

Highlighted

Re: DBRpcTask response block not called.

Dropboxer
Dropboxer
(Apologies for the delay. It looks like there was an issue with the form, and your post wasn't showing up before.)

Yes, I think that while loop might cause this. The response block runs asynchonrously, and on the main thread:

https://github.com/dropbox/dropbox-sdk-obj-c#specify-api-call-response-queue

If I understand correctly, it sounds like you're blocking the main thread, so the response block may not get a chance to run.

I recommend refactoring that to eliminate that, or use another queue or sempahores, or whatever makes sense for your app.

(Also, one shortcut on the API side of things: if you're creating folders to contain files you'll later be uploading, you can actually skip the folder creation step entirely. When uploading files via the API, any parent folders in the destination path that don't already exist will be automatically created.)
Highlighted

Re: DBRpcTask response block not called.

Explorer | Level 3

You are correct.  It was indeed a result of using the while loop to block and wait. Since the response block was running on the main thread along with my block and wait code my repsonse block would not run until the my wait loop timed out. I fixed it by adding a queueu to each call so the response block runs in a seperate thread.  It all works now.  Thank you so much for your reply.  Have a greate day!

 

Thanks,

Ray

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?