1

When I call the DBRestClient to download a file to a given path, the API does not call the loading functions.

For example:

- (void) downloadFiles:(NSMutableArray *)files
{
    NSLog(@"%@", files);
    itemsToBeDownloaded = [[NSMutableArray alloc] initWithArray:files];
    restClient = [self restClient];
    for (NSString *string in files)
    {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *filePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"/Dropbox%@", string]];
        [restClient loadFile:string intoPath:filePath];
    }
}

Printing files returns ( "/Blank.pdf" )

Printing string returns /Blank.pdf

Printing filePath returns /var/mobile/Applications/0C506400-7142-41E2-9F3D-0965985CED9E/Documents/Dropbox/Blank.pdf

So the function is called and knows the files and their path's to download.

However, when I call [restClient loadFile:string intoPath:filePath];, nothing happens. I have the delegate methods in:

- (void) restClient:(DBRestClient *)client loadedFile:(NSString *)destPath
{
    NSLog(@"Called!");
}

- (void) restClient:(DBRestClient *)client loadedFile:(NSString *)destPath contentType:(NSString *)contentType
{
     NSLog(@"Called!");
}

- (void) restClient:(DBRestClient *)client loadedFile:(NSString *)destPath contentType:(NSString *)contentType metadata:(DBMetadata *)metadata
{
    NSLog(@"%@", destPath);
    NSLog(@"%@", contentType);
    NSLog(@"%@", metadata);
}

- (void) restClient:(DBRestClient *)client loadFileFailedWithError:(NSError *)error
{
    NSLog(@"Error downloading file: %@", error);
}

No Called! statement is produced. It seems the RestClient is not downloading the data.

Another note: restClient = [self restClient]; does return a valid DBRestClient, so I know it is valid. However, the call to load the file is not being called.

Is there a specific reason the call to loadFile: is not being made? I have it loading Metadata just fine.

EDIT: a call to loadMetadata: at string does NOT call the loadMetadata delegate method.

EDIT 2: code below lists how the file's array is claimed:

- (void) downloadFiles
{
    NSMutableArray *filesToDownload = [[NSMutableArray alloc] init];
    for (int i = 0; i < [[itemsToDownload allKeys] count]; ++i)
    {
        for (NSString *string in [itemsToDownload objectForKey:[[itemsToDownload allKeys] objectAtIndex:i]])
        {
            [filesToDownload addObject:[NSString stringWithFormat:@"%@%@", [[itemsToDownload allKeys] objectAtIndex:i], string]];
        }
    }
    [dropboxController downloadFiles:filesToDownload];
}
tokan_one
  • 899
  • 7
  • 14

2 Answers2

4

So I figured out the entire problem. Turns out, you can't call the rest client methods from the background thread, it's got to be called on a main thread.

tokan_one
  • 899
  • 7
  • 14
  • This is because the DBRestClient is using NSURLConnection internally, and for the relation between NSURLConnection(used in async way) and main thread, you can refer this question for the detail: http://stackoverflow.com/questions/10535201/nsurlconnection-needs-a-nsrunloop-to-execute – Jerry Tian May 20 '13 at 06:40
0

First I thought you are calling wrong path in dropbox, but event then you should have receive error message.

If your restClient returns the delegate method even with wrong path your - (void)restClient:(DBRestClient*)client loadFileFailedWithError:(NSError*)error should have been called.

I doubt your restClient is initiated correctly.

in your .h file:

#import <DropboxSDK/DropboxSDK.h>
@property (nonatomic, strong) DBRestClient *restClient;

in.your.m file:

#import <DropboxSDK/DropboxSDK.h>
@synthesize restClient = _restClient;
- (DBRestClient *)restClient {
    if (!_restClient) {
        _restClient =
        [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
        _restClient.delegate = self;
    }
    return _restClient;
} 

then try to call your

[[self restClient] loadFile:@"string" intoPath: @"pathstring" ];

SpaceDust__
  • 4,844
  • 4
  • 43
  • 82
  • The worst part is, I've got all that in there. The app uses one centralized dropbox script that handles all dropbox operations. This script has the code present, and it works in other views. For some reason it doesn't work in the ONE view. – tokan_one May 15 '13 at 17:03
  • dropboxController is calling the restclient, it is very hard to tell without seeing your whole project, but hopefully you can get a correct answer to your problem. – SpaceDust__ May 15 '13 at 17:24